<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - widgets.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2005  Davis E. King (davis@dlib.net), Keita Mochizuki
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_WIDGETs_CPP_
<font color='#0000FF'>#define</font> DLIB_WIDGETs_CPP_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='widgets.h.html'>widgets.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>algorithm<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../string.h.html'>../string.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// toggle_button object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle min_rect <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_min_size</font><font face='Lucida Console'>(</font>name_,<font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;
        <font color='#009900'>// only change the size if it isn't going to be too small to fit the name
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>height <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> min_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            width <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> min_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,height<font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
            btn_tooltip.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_checked'></a>set_checked</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        checked <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_unchecked'></a>set_unchecked</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        checked <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> toggle_button::
    <b><a name='is_checked'></a>is_checked</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> checked;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        btn_tooltip.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        btn_tooltip.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        btn_tooltip.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string toggle_button::
    <b><a name='tooltip_text'></a>tooltip_text</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> btn_tooltip.<font color='#BB00BB'>text</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring toggle_button::
    <b><a name='tooltip_wtext'></a>tooltip_wtext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> btn_tooltip.<font color='#BB00BB'>wtext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> dlib::ustring toggle_button::
    <b><a name='tooltip_utext'></a>tooltip_utext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> btn_tooltip.<font color='#BB00BB'>utext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>name_<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        button_action::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        name_ <font color='#5555FF'>=</font> name;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        name_[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> name_[<font color='#979000'>0</font>];

        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_min_size</font><font face='Lucida Console'>(</font>name,<font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string toggle_button::
    <b><a name='name'></a>name</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wname</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring toggle_button::
    <b><a name='wname'></a>wname</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>uname</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> dlib::ustring toggle_button::
    <b><a name='uname'></a>uname</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        dlib::ustring temp <font color='#5555FF'>=</font> name_;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        temp[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> name_[<font color='#979000'>0</font>];
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> toggle_button::
    <b><a name='on_button_up'></a>on_button_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>bool</u></font> mouse_over
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>mouse_over<font face='Lucida Console'>)</font>                
        <b>{</b>
            checked <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>checked;
            <font color='#009900'>// this is a valid toggle_button click
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler_self.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler_self</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// label object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> label::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> r <font color='#5555FF'>=</font> text_color_.red;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> g <font color='#5555FF'>=</font> text_color_.green;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> b <font color='#5555FF'>=</font> text_color_.blue;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled<font face='Lucida Console'>)</font>
        <b>{</b>
            r <font color='#5555FF'>=</font> <font color='#979000'>128</font>;
            g <font color='#5555FF'>=</font> <font color='#979000'>128</font>;
            b <font color='#5555FF'>=</font> <font color='#979000'>128</font>;
        <b>}</b>

        rectangle <font color='#BB00BB'>text_rect</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

        string::size_type first, last;
        first <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        last <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>;
        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,text_rect,text_,<font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font>r,g,b<font face='Lucida Console'>)</font>,first,last<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>last <font color='#5555FF'>!</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
        <b>{</b>
            first <font color='#5555FF'>=</font> last<font color='#5555FF'>+</font><font color='#979000'>1</font>;
            last <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>\n</font>',first<font face='Lucida Console'>)</font>;
            text_rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>text_rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,text_rect,text_,<font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font>r,g,b<font face='Lucida Console'>)</font>,first,last<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> label::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text_<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>

    <font color='#0000FF'><u>void</u></font> label::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> label::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> label::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        text_ <font color='#5555FF'>=</font> text;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        text_[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> text[<font color='#979000'>0</font>];

        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width; 
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text,width,height<font face='Lucida Console'>)</font>;

        rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> width <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>; 
        rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> height <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string label::
    <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wtext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring label::
    <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>utext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> dlib::ustring label::
    <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        dlib::ustring temp <font color='#5555FF'>=</font> text_;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        temp[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> text_[<font color='#979000'>0</font>];
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> label::
    <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        m.<font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        text_color_ <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        m.<font color='#BB00BB'>unlock</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel label::
    <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> text_color_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// text_field object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle text_field::
    <b><a name='get_text_rect'></a>get_text_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#009900'>// figure out where the text string should appear        
</font>        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> vertical_pad <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;

        rectangle text_rect;
        text_rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        text_rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>vertical_pad<font face='Lucida Console'>)</font>;
        text_rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        text_rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>text_rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> text_rect;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        drawable::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='give_input_focus'></a>give_input_focus</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        has_focus <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        t.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> text_field::
    <b><a name='has_input_focus'></a>has_input_focus</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> has_focus;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='select_all_text'></a>select_all_text</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>on_select_all</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_cut'></a>on_cut</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>on_copy</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>on_delete_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_copy'></a>on_copy</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>put_on_clipboard</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_start, highlight_end<font color='#5555FF'>-</font>highlight_start<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_paste'></a>on_paste</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        ustring temp_str;
        <font color='#BB00BB'>get_from_clipboard</font><font face='Lucida Console'>(</font>temp_str<font face='Lucida Console'>)</font>;

        <font color='#009900'>// If this is a multi line string then just take the first line.
</font>        ustring::size_type pos <font color='#5555FF'>=</font> temp_str.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> ustring::npos<font face='Lucida Console'>)</font>
        <b>{</b>
            temp_str <font color='#5555FF'>=</font> temp_str.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,pos<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
        <b>{</b>
            text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,highlight_start<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> temp_str <font color='#5555FF'>+</font>
                text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_end<font color='#5555FF'>+</font><font color='#979000'>1</font>,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>highlight_end<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font color='#5555FF'>+</font>temp_str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> temp_str <font color='#5555FF'>+</font>
                text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>cursor_pos,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cursor_pos<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>+</font>temp_str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp_str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_select_all'></a>on_select_all</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        highlight_end <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>on_text_is_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_delete_selected'></a>on_delete_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
        <b>{</b>
            text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>highlight_start,highlight_end<font color='#5555FF'>-</font>highlight_start<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font face='Lucida Console'>)</font>;
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;

            <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_text_is_selected'></a>on_text_is_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>enable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>enable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>enable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_no_text_selected'></a>on_no_text_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>disable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>disable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>disable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        drawable::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        t.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        right_click_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        t.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#009900'>// adjust the height of this text field so that it is appropriate for the current
</font>        <font color='#009900'>// font size
</font>        rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text_<font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;
       
        style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_text_field</font><font face='Lucida Console'>(</font>c,rect,<font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, enabled, <font color='#5555FF'>*</font>mfont, text_, cursor_x, text_pos,
                               text_color_, bg_color_, has_focus, cursor_visible, highlight_start,
                               highlight_end<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> text.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> std::string::npos ,
                "<font color='#CC0000'>\tvoid text_field::set_text()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ttext:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        text_ <font color='#5555FF'>=</font> text.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                
        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
        
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string text_field::
    <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        std::string temp <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wtext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring text_field::
    <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        std::wstring temp <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>utext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>
    
    <font color='#0000FF'>const</font> dlib::ustring text_field::
    <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the dlib::ustring implementation.
</font>        dlib::ustring temp <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_width'></a>set_width</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width
    <font face='Lucida Console'>)</font>
    <b>{</b>        
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>width <font color='#5555FF'>&lt;</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

        rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> width <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>; 

        right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        drawable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_background_color'></a>set_background_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        bg_color_ <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel text_field::
    <b><a name='background_color'></a>background_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> bg_color_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        text_color_ <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel text_field::
    <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> text_color_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>has_focus<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>=</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                    shift_pos <font color='#5555FF'>=</font> highlight_end <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                <font color='#0000FF'>else</font>
                    shift_pos <font color='#5555FF'>=</font> highlight_start;
            <b>}</b>

            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,text_,x,y,text_pos<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,
        <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font>
            shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> double_clicked 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> btn <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>base_window::LEFT<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            has_focus <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            t.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>double_clicked<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// highlight the double clicked word
</font>                string::size_type first, last;
                <font color='#0000FF'>const</font> ustring ustr <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf8_to_utf32</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'> \t\n</font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                first <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font>.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>ustr.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                last <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>ustr.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,cursor_pos<font face='Lucida Console'>)</font>;
                <font color='#0000FF'><u>long</u></font> f <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>first<font face='Lucida Console'>)</font>;
                <font color='#0000FF'><u>long</u></font> l <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>last<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>first <font color='#5555FF'>=</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
                    f <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>last <font color='#5555FF'>=</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
                    l <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>f;
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>l;

                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>l<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                highlight_start <font color='#5555FF'>=</font> f;
                highlight_end <font color='#5555FF'>=</font> l;
                <font color='#BB00BB'>on_text_is_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::SHIFT<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>=</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_end <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                        <font color='#0000FF'>else</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_start;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        shift_pos <font color='#5555FF'>=</font> cursor_pos;
                    <b>}</b>
                <b>}</b>

                <font color='#0000FF'><u>bool</u></font> at_end <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> cursor_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    at_end <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> old_pos <font color='#5555FF'>=</font> cursor_pos;

                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,text_,x,y,text_pos<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
                shift_pos <font color='#5555FF'>=</font> cursor_pos;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>at_end <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> cursor_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> old_pos<font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus<font face='Lucida Console'>)</font>
        <b>{</b>
            t.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>focus_lost_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>focus_lost_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// If the right click menu is up then we don't want to do anything with
</font>        <font color='#009900'>// the keyboard ourselves.  Let the popup menu use the keyboard for now.
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>right_click_menu.<font color='#BB00BB'>popup_menu_visible</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>const</font> ustring space_str <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf8_to_utf32</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'> \t\n</font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>bool</u></font> shift <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::KBD_MOD_SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>bool</u></font> ctrl <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::KBD_MOD_CONTROL<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> is_printable <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>=</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_end <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                        <font color='#0000FF'>else</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_start;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        shift_pos <font color='#5555FF'>=</font> cursor_pos;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_LEFT <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
                key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_UP<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// find the first non-whitespace to our left
</font>                        std::string::size_type pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_last_not_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                        <b>{</b>
                            pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,pos<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>else</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <b>}</b>
                        <font color='#0000FF'>else</font>
                        <b>{</b>
                            new_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <b>}</b>
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        new_pos <font color='#5555FF'>=</font> cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <b>}</b>

                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>

            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_RIGHT <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
                key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DOWN<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// find the first non-whitespace to our left
</font>                        std::string::size_type pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_not_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                        <b>{</b>
                            pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,pos<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>else</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>else</font>
                        <b>{</b>
                            new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        new_pos <font color='#5555FF'>=</font> cursor_pos<font color='#5555FF'>+</font><font color='#979000'>1</font>;
                    <b>}</b>

                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_printable<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>a</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_select_all</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>c</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_copy</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>v</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_paste</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>x</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_cut</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>!</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                    <b>{</b>
                        text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,highlight_start<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>unichar<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
                            text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_end<font color='#5555FF'>+</font><font color='#979000'>1</font>,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>highlight_end<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                        highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                        <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>unichar<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
                            text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>cursor_pos,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
                    mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,text_width,height,text_pos<font face='Lucida Console'>)</font>;

                    <font color='#009900'>// send out the text modified event
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enter_key_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>enter_key_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_BACKSPACE<font face='Lucida Console'>)</font>
            <b>{</b>                
                <font color='#009900'>// if something is highlighted then delete that
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>on_delete_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                    <font color='#009900'>// send out the text modified event
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#009900'>// do this just so it repaints itself right
</font>                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,text_width,height,text_pos<font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DELETE<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if something is highlighted then delete that
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>on_delete_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>cursor_pos,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                    <font color='#009900'>// send out the text modified event
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#009900'>// do this just so it repaints itself right
</font>                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font face='Lucida Console'>)</font>;
                <b>}</b>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,text_width,height,text_pos<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_HOME<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_END<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            recent_movement <font color='#5555FF'>=</font> <font color='#979000'>true</font>;

        <b>}</b>
    <b>}</b>

<font color='#009900'>// ---------------------------------------------------------------------------------------- 
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='on_string_put'></a>on_string_put</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring <font color='#5555FF'>&amp;</font>str
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font><b>{</b>
            ustring ustr <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
            <b>{</b>
                text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,highlight_start<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> ustr <font color='#5555FF'>+</font>
                    text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_end<font color='#5555FF'>+</font><font color='#979000'>1</font>,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>highlight_end<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font color='#5555FF'>+</font>ustr.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> ustr <font color='#5555FF'>+</font>
                    text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>cursor_pos,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cursor_pos<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>+</font>ustr.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,text_width,height,text_pos<font face='Lucida Console'>)</font>;

            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>
    
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_field::
    <b><a name='move_cursor'></a>move_cursor</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> pos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> old_cursor_pos <font color='#5555FF'>=</font> cursor_pos;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_pos <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> pos<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// the cursor should go all the way to the left side of the text
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>6</font><font face='Lucida Console'>)</font>
                text_pos <font color='#5555FF'>=</font> pos<font color='#5555FF'>-</font><font color='#979000'>6</font>;
            <font color='#0000FF'>else</font>
                text_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

            cursor_pos <font color='#5555FF'>=</font> pos;    
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,text_width,height,text_pos<font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_x <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>cursor_pos<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_pos<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,width,height,text_pos,cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    new_x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> width <font color='#5555FF'>-</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>right_overflow</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            cursor_x <font color='#5555FF'>=</font> new_x;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,width,height,text_pos,pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_x <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                width <font color='#5555FF'>-</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>right_overflow</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// move the text to the left if necessary
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_x <font color='#5555FF'>+</font> <font color='#979000'>4</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>new_x <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    new_x <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>[text_[text_pos]].<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#5555FF'>+</font><font color='#5555FF'>+</font>text_pos;
                <b>}</b>
            <b>}</b>

            cursor_x <font color='#5555FF'>=</font> new_x;
            cursor_pos <font color='#5555FF'>=</font> pos;     
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_,text_width,height,text_pos<font face='Lucida Console'>)</font>;
        <b>}</b>

        parent.<font color='#BB00BB'>set_im_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>cursor_x, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>old_cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
            <b>{</b>
                highlight_start <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>shift_pos,cursor_pos<font face='Lucida Console'>)</font>;
                highlight_end <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>shift_pos,cursor_pos<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&gt;</font> highlight_end<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>on_text_is_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            recent_movement <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//             tabbed_display object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    tabbed_display::
    <b><a name='tabbed_display'></a>tabbed_display</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> : 
        drawable<font face='Lucida Console'>(</font>w,MOUSE_CLICK<font face='Lucida Console'>)</font>,
        selected_tab_<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        left_pad<font face='Lucida Console'>(</font><font color='#979000'>6</font><font face='Lucida Console'>)</font>,
        right_pad<font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>,
        top_pad<font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>,
        bottom_pad<font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>
    <b>{</b>
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>40</font>,mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>top_pad<font color='#5555FF'>+</font>bottom_pad<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        tabs.<font color='#BB00BB'>set_max_size</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        tabs.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    tabbed_display::
    ~<b><a name='tabbed_display'></a>tabbed_display</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// we have to adjust the positions of all the tab rectangles
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> xdelta <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> x;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> ydelta <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> y;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            tabs[i].rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>tabs[i].rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>xdelta<font face='Lucida Console'>)</font>;
            tabs[i].rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>tabs[i].rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>xdelta<font face='Lucida Console'>)</font>;

            tabs[i].rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>tabs[i].rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>ydelta<font face='Lucida Console'>)</font>;
            tabs[i].rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>tabs[i].rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>ydelta<font face='Lucida Console'>)</font>;


            <font color='#009900'>// adjust the position of the group associated with this tab if it exists
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[i].group<font face='Lucida Console'>)</font>
                tabs[i].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>+</font><font color='#979000'>3</font>, y<font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>top_pad<font color='#5555FF'>+</font>bottom_pad<font color='#5555FF'>+</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        drawable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>recompute_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='fit_to_contents'></a>fit_to_contents</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle new_rect;
        point <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        new_rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[i].group<font face='Lucida Console'>)</font>
            <b>{</b>
                tabs[i].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>fit_to_contents</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                new_rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> tabs[i].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// and give the new rect an additional 4 pixels on the bottom and right sides
</font>        <font color='#009900'>// so that the contents to hit the edge of the tabbed display
</font>        new_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>new_rect, new_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>4</font>, new_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>new_rect<font color='#5555FF'>+</font>rect<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> new_rect;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> x <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> y <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>+</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>y<font color='#5555FF'>+</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>recompute_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_number_of_tabs'></a>set_number_of_tabs</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> num <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> ,
                "<font color='#CC0000'>\tvoid tabbed_display::set_number_of_tabs()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnum:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> num <font face='Lucida Console'>)</font>;

        tabs.<font color='#BB00BB'>set_max_size</font><font face='Lucida Console'>(</font>num<font face='Lucida Console'>)</font>;
        tabs.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>num<font face='Lucida Console'>)</font>;

        selected_tab_ <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#BB00BB'>recompute_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> tabbed_display::
    <b><a name='number_of_tabs'></a>number_of_tabs</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string tabbed_display::
    <b><a name='tab_name'></a>tab_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tab_wname</font><font face='Lucida Console'>(</font>idx<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>
    
    <font color='#0000FF'>const</font> std::wstring tabbed_display::
    <b><a name='tab_wname'></a>tab_wname</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tab_uname</font><font face='Lucida Console'>(</font>idx<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>
    
    <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> tabbed_display::
    <b><a name='tab_uname'></a>tab_uname</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tvoid tabbed_display::tab_name()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_tabs(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> tabs[idx].name;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_tab_name'></a>set_tab_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> new_name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_tab_name</font><font face='Lucida Console'>(</font>idx, <font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>new_name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_tab_name'></a>set_tab_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> new_name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_tab_name</font><font face='Lucida Console'>(</font>idx, <font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>new_name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_tab_name'></a>set_tab_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> new_name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;


        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tvoid tabbed_display::set_tab_name()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_tabs(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;


        tabs[idx].name <font color='#5555FF'>=</font> new_name;
        <font color='#009900'>// do this so that there isn't any reference counting going on
</font>        tabs[idx].name[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> tabs[idx].name[<font color='#979000'>0</font>];
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>new_name,tabs[idx].width,height<font face='Lucida Console'>)</font>;


        <font color='#BB00BB'>recompute_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            rectangle temp <font color='#5555FF'>=</font> rect;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> offset <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> bottom_pad <font color='#5555FF'>+</font> top_pad;
            temp.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// now we have to figure out which tab was clicked
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_tab_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> i <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> tabs[i].rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                        tabs[selected_tab_].rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> old_idx <font color='#5555FF'>=</font> selected_tab_;
                        selected_tab_ <font color='#5555FF'>=</font> i;
                        <font color='#BB00BB'>recompute_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;

                        <font color='#009900'>// adjust the widget_group objects for these tabs if they exist
</font>                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[i].group<font face='Lucida Console'>)</font>
                            tabs[i].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[old_idx].group<font face='Lucida Console'>)</font>
                            tabs[old_idx].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font>i,old_idx<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>break</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_tab_group'></a>set_tab_group</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        widget_group<font color='#5555FF'>&amp;</font> group
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tvoid tabbed_display::set_tab_group()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_tabs(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;


        tabs[idx].group <font color='#5555FF'>=</font> <font color='#5555FF'>&amp;</font>group;
        group.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>3</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>top_pad<font color='#5555FF'>+</font>bottom_pad<font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>idx <font color='#5555FF'>=</font><font color='#5555FF'>=</font> selected_tab_<font face='Lucida Console'>)</font>
            group.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            group.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[selected_tab_].group<font face='Lucida Console'>)</font>
            tabs[selected_tab_].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[selected_tab_].group<font face='Lucida Console'>)</font>
            tabs[selected_tab_].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[selected_tab_].group<font face='Lucida Console'>)</font>
            tabs[selected_tab_].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tabs[selected_tab_].group<font face='Lucida Console'>)</font>
            tabs[selected_tab_].group<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#009900'>// draw the main border first
</font>        rectangle <font color='#BB00BB'>main_box</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>top_pad<font color='#5555FF'>+</font>bottom_pad,rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_button_up</font><font face='Lucida Console'>(</font>c,main_box<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_pixel</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>main_box.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>,main_box.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>128</font>,<font color='#979000'>128</font>,<font color='#979000'>128</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        rgb_pixel color;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled<font face='Lucida Console'>)</font>
        <b>{</b>
            color.red <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            color.green <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            color.blue <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            color.red <font color='#5555FF'>=</font> <font color='#979000'>128</font>;
            color.green <font color='#5555FF'>=</font> <font color='#979000'>128</font>;
            color.blue <font color='#5555FF'>=</font> <font color='#979000'>128</font>;
        <b>}</b>

        <font color='#009900'>// draw the tabs
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_tab_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>draw_tab</font><font face='Lucida Console'>(</font>tabs[i].rect,c<font face='Lucida Console'>)</font>;

            <font color='#009900'>// draw the name string
</font>            rectangle temp <font color='#5555FF'>=</font> tabs[i].rect;
            temp.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>top_pad<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>bottom_pad<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>left_pad<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>right_pad<font face='Lucida Console'>)</font>;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,temp,tabs[i].name,color<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#BB00BB'>draw_tab</font><font face='Lucida Console'>(</font>tabs[selected_tab_].rect,c<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,
            <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tabs[selected_tab_].rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,
            tabs[selected_tab_].rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tabs[selected_tab_].rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font>,
            tabs[selected_tab_].rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>212</font>,<font color='#979000'>208</font>,<font color='#979000'>200</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='draw_tab'></a>draw_tab</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> tab,
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>const</font> rgb_pixel <font color='#BB00BB'>white</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> rgb_pixel <font color='#BB00BB'>background</font><font face='Lucida Console'>(</font><font color='#979000'>212</font>,<font color='#979000'>208</font>,<font color='#979000'>200</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> rgb_pixel <font color='#BB00BB'>dark_gray</font><font face='Lucida Console'>(</font><font color='#979000'>64</font>,<font color='#979000'>64</font>,<font color='#979000'>64</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> rgb_pixel <font color='#BB00BB'>gray</font><font face='Lucida Console'>(</font><font color='#979000'>128</font>,<font color='#979000'>128</font>,<font color='#979000'>128</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,tab.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,tab.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,background<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,tab.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,dark_gray<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>,tab.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,gray<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_pixel</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_pixel</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>tab.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>,tab.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,dark_gray<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>tabs[i].name,tabs[i].width,height<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#BB00BB'>recompute_tabs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> tabbed_display::
    <b><a name='recompute_tabs'></a>recompute_tabs</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> offset <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> bottom_pad <font color='#5555FF'>+</font> top_pad;


        <font color='#009900'>// figure out the size and position of all the tabs
</font>        rectangle sel_tab_rect, other_tab;
        sel_tab_rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        sel_tab_rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset<font face='Lucida Console'>)</font>;

        other_tab.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        other_tab.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>long</u></font> cur_x <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> str_width <font color='#5555FF'>=</font> tabs[i].width;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_tab_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
            <b>{</b>
                other_tab.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>cur_x<font face='Lucida Console'>)</font>;
                cur_x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> left_pad <font color='#5555FF'>+</font> str_width <font color='#5555FF'>+</font> right_pad;
                other_tab.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>cur_x<font face='Lucida Console'>)</font>;
                tabs[i].rect <font color='#5555FF'>=</font> other_tab;
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cur_x;

            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    sel_tab_rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>cur_x<font color='#5555FF'>-</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font>
                    sel_tab_rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>cur_x<font face='Lucida Console'>)</font>;

                cur_x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> left_pad <font color='#5555FF'>+</font> str_width <font color='#5555FF'>+</font> right_pad;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>!</font><font color='#5555FF'>=</font> tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                    sel_tab_rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>cur_x<font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font>
                    sel_tab_rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>cur_x<font face='Lucida Console'>)</font>;
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cur_x;

                tabs[i].rect <font color='#5555FF'>=</font> sel_tab_rect;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// make sure this object is wide enough
</font>        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> last <font color='#5555FF'>=</font> tabs[tabs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>].rect;
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> first <font color='#5555FF'>=</font> tabs[<font color='#979000'>0</font>].rect;
        rect <font color='#5555FF'>=</font> last <font color='#5555FF'>+</font> rect <font color='#5555FF'>+</font> first;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//             named_rectangle object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    named_rectangle::
    <b><a name='named_rectangle'></a>named_rectangle</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> :
        drawable<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        name_width<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        name_height<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>make_name_fit_in_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    named_rectangle::
    ~<b><a name='named_rectangle'></a>named_rectangle</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> x <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> y <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>+</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>y<font color='#5555FF'>+</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>make_name_fit_in_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='wrap_around'></a>wrap_around</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> pad <font color='#5555FF'>=</font> name_height<font color='#5555FF'>/</font><font color='#979000'>2</font>;

        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>pad, r.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>name_height<font color='#5555FF'>*</font><font color='#979000'>4</font><font color='#5555FF'>/</font><font color='#979000'>3</font>, r.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>pad, r.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>pad<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>make_name_fit_in_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>name_,name_width,name_height<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>make_name_fit_in_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='make_name_fit_in_rect'></a>make_name_fit_in_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure the named rectangle is big enough to contain the name
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> wtemp <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> name_width;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> htemp <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> name_height;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> wtemp<font face='Lucida Console'>)</font>
            rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> wtemp <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> htemp<font face='Lucida Console'>)</font>
            rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> htemp <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        name_ <font color='#5555FF'>=</font> name.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>name_,name_width,name_height<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>make_name_fit_in_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string named_rectangle::
    <b><a name='name'></a>name</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wname</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring named_rectangle::
    <b><a name='wname'></a>wname</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>uname</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> dlib::ustring named_rectangle::
    <b><a name='uname'></a>uname</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> dlib::<font color='#BB00BB'>ustring</font><font face='Lucida Console'>(</font>name_.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> named_rectangle::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;
        
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> gap <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        rectangle strrect <font color='#5555FF'>=</font> rect;
        strrect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> gap<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rtop <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> name_height<font color='#5555FF'>/</font><font color='#979000'>2</font>;

        <font color='#0000FF'>const</font> rgb_pixel <font color='#BB00BB'>white</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> rgb_pixel <font color='#BB00BB'>gray</font><font face='Lucida Console'>(</font><font color='#979000'>128</font>,<font color='#979000'>128</font>,<font color='#979000'>128</font><font face='Lucida Console'>)</font>;

        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,strrect,name_<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rtop<font face='Lucida Console'>)</font>,             
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>gap<font color='#5555FF'>/</font><font color='#979000'>2</font>, rtop<font face='Lucida Console'>)</font>, gray<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rtop<font face='Lucida Console'>)</font>,             
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, gray<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,  
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, gray<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, rtop<font face='Lucida Console'>)</font>,          
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, gray<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>strrect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> name_width <font color='#5555FF'>+</font> <font color='#979000'>2</font>, rtop<font face='Lucida Console'>)</font>, 
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, rtop<font face='Lucida Console'>)</font>, gray<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>strrect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> name_width <font color='#5555FF'>+</font> <font color='#979000'>2</font>, rtop<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,   
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font>, rtop<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rtop<font face='Lucida Console'>)</font>, 
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,                
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, rtop<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, 
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, white<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, rtop<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, 
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>gap<font color='#5555FF'>/</font><font color='#979000'>2</font>, rtop<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, white<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class mouse_tracker
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    mouse_tracker::
    <b><a name='mouse_tracker'></a>mouse_tracker</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> :
        draggable<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        offset<font face='Lucida Console'>(</font><font color='#979000'>18</font><font face='Lucida Console'>)</font>,
        nr<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        x_label<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        y_label<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        click_x<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        click_y<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_draggable_area</font><font face='Lucida Console'>(</font><font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>500</font>,<font color='#979000'>500</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        x_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>x: </font>"<font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>y: </font>"<font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>mouse position</font>"<font face='Lucida Console'>)</font>;


        x_label.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>offset,offset<font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;

        nr.<font color='#BB00BB'>wrap_around</font><font face='Lucida Console'>(</font>x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> y_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> nr.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font><font color='#979000'>2000000000</font><font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font><font color='#979000'>2000000001</font><font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font><font color='#979000'>2000000001</font><font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font><font color='#979000'>2000000001</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    mouse_tracker::
    ~<b><a name='mouse_tracker'></a>mouse_tracker</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b> 
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>set_main_font</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>set_main_font</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>set_main_font</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        nr.<font color='#BB00BB'>wrap_around</font><font face='Lucida Console'>(</font>x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> y_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> nr.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        draggable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset<font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        draggable::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        draggable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        draggable::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        draggable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        nr.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> double_clicked 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        draggable::<font color='#BB00BB'>on_mouse_down</font><font face='Lucida Console'>(</font>btn,state,x,y,double_clicked<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>x,y,x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>click_x,click_y,click_x,click_y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            click_x <font color='#5555FF'>=</font> x;
            click_y <font color='#5555FF'>=</font> y;

            y_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>y: 0</font>"<font face='Lucida Console'>)</font>;
            x_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>x: 0</font>"<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled<font face='Lucida Console'>)</font>
        <b>{</b>
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            draggable::<font color='#BB00BB'>on_mouse_move</font><font face='Lucida Console'>(</font>state,x,y<font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>long</u></font> dx <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'><u>long</u></font> dy <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_x <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                dx <font color='#5555FF'>=</font> click_x;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_y <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                dy <font color='#5555FF'>=</font> click_y;

            sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font>"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
            sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>y: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> y <font color='#5555FF'>-</font> dy;
            y_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font>"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
            sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>x: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> x <font color='#5555FF'>-</font> dx;
            x_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='on_drag'></a>on_drag</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        nr.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        x_label.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset<font face='Lucida Console'>)</font>;
        y_label.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, x_label.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>long</u></font> x <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'><u>long</u></font> y <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_x <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
            x <font color='#5555FF'>=</font> click_x;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_y <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
            y <font color='#5555FF'>=</font> click_y;

        sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font>"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
        sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>y: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> lasty <font color='#5555FF'>-</font> y;
        y_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font>"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
        sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>x: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> lastx <font color='#5555FF'>-</font> x;
        x_label.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_tracker::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
    <b>{</b> 
        <font color='#BB00BB'>fill_rect</font><font face='Lucida Console'>(</font>c, rect,<font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>212</font>,<font color='#979000'>208</font>,<font color='#979000'>200</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_pixel</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>click_x,click_y<font face='Lucida Console'>)</font>,<font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class list_box
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> list_box_helper<b>{</b>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='list_box'></a>list_box</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> : 
        scrollable_region<font face='Lucida Console'>(</font>w,MOUSE_WHEEL<font color='#5555FF'>|</font>MOUSE_CLICK<font face='Lucida Console'>)</font>,
        ms_enabled<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        last_selected<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_vertical_scroll_increment</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_horizontal_scroll_increment</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>list_box_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    ~<b><a name='list_box'></a>list_box</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#009900'>// recompute the sizes of all the items
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>items[i].name,items[i].width, items[i].height<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#BB00BB'>set_vertical_scroll_increment</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='is_selected'></a>is_selected</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> index <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tbool list_box::is_selected(index)</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tindex:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> index 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tsize(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> items[index].is_selected;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='select'></a>select</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> index <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tvoid list_box::select(index)</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tindex:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> index 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tsize(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;

        last_selected <font color='#5555FF'>=</font> index;
        items[index].is_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='unselect'></a>unselect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> index <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tvoid list_box::unselect(index)</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tindex:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> index 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tsize(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
        items[index].is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> S<font color='#5555FF'>&amp;</font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::<b><a name='operator'></a>operator</b> [] <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> index <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tconst std::string&amp; list_box::operator[](index)</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tindex:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> index 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tsize(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items[index].name;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='multiple_select_enabled'></a>multiple_select_enabled</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> ms_enabled;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='enable_multiple_select'></a>enable_multiple_select</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        ms_enabled <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='disable_multiple_select'></a>disable_multiple_select</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        ms_enabled <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='at_start'></a>at_start</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>at_start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='reset'></a>reset</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        items.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='current_element_valid'></a>current_element_valid</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>current_element_valid</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> S <font color='#5555FF'>&amp;</font>list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='element'></a>element</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> <font color='#BB00BB'>current_element_valid</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tconst std::string&amp; list_box::element()</font>"
                 <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.name;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> S <font color='#5555FF'>&amp;</font>list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='element'></a>element</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> <font color='#BB00BB'>current_element_valid</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                "<font color='#CC0000'>\tconst std::string&amp; list_box::element()</font>"
                 <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.name;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='move_next'></a>move_next</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='size'></a>size</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>draw</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;

        rectangle area <font color='#5555FF'>=</font> <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_list_box_background</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, enabled<font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>long</u></font> y <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y<font color='#5555FF'>+</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>items[i].height <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                y <font color='#5555FF'>+</font><font color='#5555FF'>=</font> items[i].height;
                <font color='#0000FF'>continue</font>;
            <b>}</b>

            rectangle <font color='#BB00BB'>r</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, y, <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, y<font color='#5555FF'>+</font>items[i].height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_list_box_item</font><font face='Lucida Console'>(</font>c,r, <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, enabled, <font color='#5555FF'>*</font>mfont, items[i].name, items[i].is_selected<font face='Lucida Console'>)</font>;


            y <font color='#5555FF'>+</font><font color='#5555FF'>=</font> items[i].height;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y <font color='#5555FF'>&gt;</font> area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>break</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> is_double_click
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> ms_enabled <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> 
                 <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::CONTROL<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font><font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                items.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>items.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    items.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <b>}</b>
            <b>}</b>

            y <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> h <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                h <font color='#5555FF'>+</font><font color='#5555FF'>=</font> items[i].height;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>h <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> y<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ms_enabled<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::CONTROL<font face='Lucida Console'>)</font>
                        <b>{</b>
                            items[i].is_selected <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>items[i].is_selected;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>items[i].is_selected<font face='Lucida Console'>)</font>
                                last_selected <font color='#5555FF'>=</font> i;
                        <b>}</b>
                        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#009900'>// we want to select everything between (and including) the
</font>                            <font color='#009900'>// current thing clicked and last_selected.
</font>                            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> first <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>i,last_selected<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> last <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>i,last_selected<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> first; j <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> last; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
                                items[j].is_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                        <b>}</b>
                        <font color='#0000FF'>else</font>
                        <b>{</b>
                            items[i].is_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                            last_selected <font color='#5555FF'>=</font> i;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_double_click <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                                <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>single_click_event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                                <font color='#BB00BB'>single_click_event_handler</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        items[i].is_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                        last_selected <font color='#5555FF'>=</font> i;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_double_click <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>single_click_event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>single_click_event_handler</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                    <b>}</b>

                    <font color='#0000FF'>break</font>;
                <b>}</b>
            <b>}</b>

            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> list_box<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font>::
    <b><a name='get_selected'></a>get_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> <font color='#BB00BB'>multiple_select_enabled</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
                "<font color='#CC0000'>\tunsigned long list_box::get_selected()</font>"
                 <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>items[i].is_selected<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> i;
        <b>}</b>
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
   <font color='#009900'>// making instance of template
</font>   <font color='#0000FF'>template</font> <font color='#0000FF'>class</font> <b><a name='list_box'></a>list_box</b><font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font>;
   <font color='#0000FF'>template</font> <font color='#0000FF'>class</font> <b><a name='list_box'></a>list_box</b><font color='#5555FF'>&lt;</font>std::wstring<font color='#5555FF'>&gt;</font>;
   <font color='#0000FF'>template</font> <font color='#0000FF'>class</font> <b><a name='list_box'></a>list_box</b><font color='#5555FF'>&lt;</font>dlib::ustring<font color='#5555FF'>&gt;</font>;
   <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// function message_box()  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> message_box_helper
    <b>{</b>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='initialize'></a>initialize</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            msg.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>20</font>,<font color='#979000'>20</font><font face='Lucida Console'>)</font>;
            msg.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>message<font face='Lucida Console'>)</font>;
            rectangle msg_rect <font color='#5555FF'>=</font> msg.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>OK</font>"<font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#979000'>60</font>,btn_ok.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>msg_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>60</font><font face='Lucida Console'>)</font>
                btn_ok.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>msg_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font>msg_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>btn_ok.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>,msg_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>15</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                btn_ok.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>20</font>,msg_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>15</font><font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_click<font face='Lucida Console'>)</font>;

            rectangle size <font color='#5555FF'>=</font> btn_ok.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> msg_rect;
            <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>size.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>20</font>,size.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>20</font><font face='Lucida Console'>)</font>;


            <font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>set_title</font><font face='Lucida Console'>(</font>title<font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        box_win::
        <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title_,
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message_
        <font face='Lucida Console'>)</font> : 
            drawable_window<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            title<font face='Lucida Console'>(</font>convert_mbstring_to_wstring<font face='Lucida Console'>(</font>title_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            message<font face='Lucida Console'>(</font>convert_mbstring_to_wstring<font face='Lucida Console'>(</font>message_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            msg<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>initialize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        box_win::
        <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> title_,
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> message_
        <font face='Lucida Console'>)</font> : 
            drawable_window<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            title<font face='Lucida Console'>(</font>title_<font face='Lucida Console'>)</font>,
            message<font face='Lucida Console'>(</font>message_<font face='Lucida Console'>)</font>,
            msg<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>initialize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        box_win::
        <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> title_,
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> message_
        <font face='Lucida Console'>)</font> : 
            drawable_window<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            title<font face='Lucida Console'>(</font>convert_utf32_to_wstring<font face='Lucida Console'>(</font>title_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            message<font face='Lucida Console'>(</font>convert_utf32_to_wstring<font face='Lucida Console'>(</font>message_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            msg<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>initialize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        box_win::
        ~<b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='deleter_thread'></a>deleter_thread</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>void</u></font><font color='#5555FF'>*</font> param
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// The point of this extra event_handler stuff is to allow the user
</font>            <font color='#009900'>// to end the program from within the callback.  So we want to destroy the 
</font>            <font color='#009900'>// window *before* we call their callback.
</font>            box_win<font color='#5555FF'>&amp;</font> w <font color='#5555FF'>=</font> <font color='#5555FF'>*</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>box_win<font color='#5555FF'>*</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>param<font face='Lucida Console'>)</font>;
            w.<font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font>w.event_handler<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>delete</font> <font color='#5555FF'>&amp;</font>w;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_click'></a>on_click</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>create_new_thread</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>deleter_thread,<font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        base_window::on_close_return_code box_win::
        <b><a name='on_window_close'></a>on_window_close</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// The point of this extra event_handler stuff is to allow the user
</font>            <font color='#009900'>// to end the program within the callback.  So we want to destroy the 
</font>            <font color='#009900'>// window *before* we call their callback. 
</font>            any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>event_handler_copy</font><font face='Lucida Console'>(</font>event_handler<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>delete</font> <font color='#0000FF'>this</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler_copy.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler_copy</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> CLOSE_WINDOW;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> blocking_box_win::
        <b><a name='initialize'></a>initialize</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            msg.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>20</font>,<font color='#979000'>20</font><font face='Lucida Console'>)</font>;
            msg.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>message<font face='Lucida Console'>)</font>;
            rectangle msg_rect <font color='#5555FF'>=</font> msg.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>OK</font>"<font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#979000'>60</font>,btn_ok.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>msg_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>60</font><font face='Lucida Console'>)</font>
                btn_ok.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>msg_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font>msg_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>btn_ok.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>,msg_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>15</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                btn_ok.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>20</font>,msg_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>15</font><font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>blocking_box_win::on_click<font face='Lucida Console'>)</font>;

            rectangle size <font color='#5555FF'>=</font> btn_ok.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> msg_rect;
            <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>size.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>20</font>,size.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>20</font><font face='Lucida Console'>)</font>;


            <font color='#BB00BB'>set_title</font><font face='Lucida Console'>(</font>title<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        blocking_box_win::
        <b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title_,
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message_
        <font face='Lucida Console'>)</font> : 
            drawable_window<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            title<font face='Lucida Console'>(</font>convert_mbstring_to_wstring<font face='Lucida Console'>(</font>title_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            message<font face='Lucida Console'>(</font>convert_mbstring_to_wstring<font face='Lucida Console'>(</font>message_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            msg<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>initialize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        blocking_box_win::
        <b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> title_,
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> message_
        <font face='Lucida Console'>)</font> : 
            drawable_window<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            title<font face='Lucida Console'>(</font>title_<font face='Lucida Console'>)</font>,
            message<font face='Lucida Console'>(</font>message_<font face='Lucida Console'>)</font>,
            msg<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>initialize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        blocking_box_win::
        <b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> title_,
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> message_
        <font face='Lucida Console'>)</font> : 
            drawable_window<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            title<font face='Lucida Console'>(</font>convert_utf32_to_wstring<font face='Lucida Console'>(</font>title_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            message<font face='Lucida Console'>(</font>convert_utf32_to_wstring<font face='Lucida Console'>(</font>message_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            msg<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>initialize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        blocking_box_win::
        ~<b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b> 
            <font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> blocking_box_win::
        <b><a name='on_click'></a>on_click</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// function open_file_box() 
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> open_file_box_helper
    <b>{</b>
        box_win::
        <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title,
            <font color='#0000FF'><u>bool</u></font> has_text_field 
        <font face='Lucida Console'>)</font> : 
            lbl_dirs<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            lbl_files<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            lbl_file_name<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            lb_dirs<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            lb_files<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_ok<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_cancel<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            btn_root<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
            tf_file_name<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_text_field <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                tf_file_name.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                lbl_file_name.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                lbl_file_name.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>File: </font>"<font face='Lucida Console'>)</font>;
            <b>}</b>

            cur_dir <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#979000'>500</font>,<font color='#979000'>300</font><font face='Lucida Console'>)</font>;

            lbl_dirs.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Directories:</font>"<font face='Lucida Console'>)</font>;
            lbl_files.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Files:</font>"<font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Ok</font>"<font face='Lucida Console'>)</font>;
            btn_cancel.<font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Cancel</font>"<font face='Lucida Console'>)</font>;
            btn_root.<font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>/</font>"<font face='Lucida Console'>)</font>;

            btn_root.<font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_root_click<font face='Lucida Console'>)</font>;
            btn_cancel.<font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_cancel_click<font face='Lucida Console'>)</font>;
            btn_ok.<font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_open_click<font face='Lucida Console'>)</font>;
            lb_dirs.<font color='#BB00BB'>set_double_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_dirs_click<font face='Lucida Console'>)</font>;
            lb_files.<font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_files_click<font face='Lucida Console'>)</font>;
            lb_files.<font color='#BB00BB'>set_double_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_files_double_click<font face='Lucida Console'>)</font>;


            btn_root.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>5</font>,<font color='#979000'>5</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>set_sizes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>set_title</font><font face='Lucida Console'>(</font>title<font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>on_root_click</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// make it so that the file box starts out in our current working
</font>            <font color='#009900'>// directory
</font>            std::string <font color='#BB00BB'>full_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_current_dir</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>full_name.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                std::string::size_type pos <font color='#5555FF'>=</font> full_name.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>\\/</font>"<font face='Lucida Console'>)</font>;
                std::string <font color='#BB00BB'>left</font><font face='Lucida Console'>(</font>full_name.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,pos<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                    full_name <font color='#5555FF'>=</font> full_name.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font>
                    full_name.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>left.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>enter_folder</font><font face='Lucida Console'>(</font>left<font face='Lucida Console'>)</font>; 
            <b>}</b>


            <font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        box_win::
        ~<b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='set_sizes'></a>set_sizes</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, height;
            <font color='#BB00BB'>get_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lbl_file_name.<font color='#BB00BB'>is_hidden</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                lbl_dirs.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,btn_root.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,lbl_dirs.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>/</font><font color='#979000'>2</font>,height<font color='#5555FF'>-</font>lb_dirs.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>btn_cancel.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>;

                lbl_files.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>lb_dirs.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,btn_root.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>lb_dirs.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,lbl_files.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font>lb_files.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,height<font color='#5555FF'>-</font>lb_files.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>btn_cancel.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>;

                btn_ok.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>width <font color='#5555FF'>-</font> btn_ok.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>25</font>,lb_files.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                btn_cancel.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>btn_ok.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> btn_cancel.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>5</font>,lb_files.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>

                lbl_dirs.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,btn_root.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,lbl_dirs.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>/</font><font color='#979000'>2</font>,height<font color='#5555FF'>-</font>lb_dirs.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>btn_cancel.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>10</font><font color='#5555FF'>-</font>tf_file_name.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                lbl_files.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>lb_dirs.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,btn_root.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>lb_dirs.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,lbl_files.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font>lb_files.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,height<font color='#5555FF'>-</font>lb_files.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>btn_cancel.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>10</font><font color='#5555FF'>-</font>tf_file_name.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                lbl_file_name.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>lb_files.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, lb_files.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>;
                tf_file_name.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>lbl_file_name.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, lb_files.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                tf_file_name.<font color='#BB00BB'>set_width</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font>tf_file_name.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;

                btn_ok.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>width <font color='#5555FF'>-</font> btn_ok.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>25</font>,tf_file_name.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
                btn_cancel.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>btn_ok.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> btn_cancel.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>5</font>,tf_file_name.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
            <b>}</b>

        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_window_resized'></a>on_window_resized</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_sizes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='deleter_thread'></a>deleter_thread</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> 
        <b>{</b>  
            <font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>delete</font> <font color='#0000FF'>this</font>; 
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='enter_folder'></a>enter_folder</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> folder_name
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn_root.<font color='#BB00BB'>is_checked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                btn_root.<font color='#BB00BB'>set_unchecked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cur_dir <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                sob[cur_dir]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_unchecked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;


            <font color='#0000FF'>const</font> std::string old_path <font color='#5555FF'>=</font> path;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> old_cur_dir <font color='#5555FF'>=</font> cur_dir;

            scoped_ptr<font color='#5555FF'>&lt;</font>toggle_button<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>new_btn</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>toggle_button</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            new_btn<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>folder_name<font face='Lucida Console'>)</font>;
            new_btn<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>box_win::on_path_button_click<font face='Lucida Console'>)</font>;

            <font color='#009900'>// remove any path buttons that won't be part of the path anymore
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>cur_dir<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    scoped_ptr<font color='#5555FF'>&lt;</font>toggle_button<font color='#5555FF'>&gt;</font> junk;
                    sob.<font color='#BB00BB'>remove</font><font face='Lucida Console'>(</font>cur_dir<font color='#5555FF'>+</font><font color='#979000'>1</font>,junk<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                new_btn<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>sob[sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font>,sob[sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                new_btn<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>btn_root.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>5</font>,btn_root.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            cur_dir <font color='#5555FF'>=</font> sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            sob.<font color='#BB00BB'>add</font><font face='Lucida Console'>(</font>sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,new_btn<font face='Lucida Console'>)</font>;

            path <font color='#5555FF'>+</font><font color='#5555FF'>=</font> folder_name <font color='#5555FF'>+</font> directory::<font color='#BB00BB'>get_separator</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>set_dir</font><font face='Lucida Console'>(</font>prefix <font color='#5555FF'>+</font> path<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                sob.<font color='#BB00BB'>remove</font><font face='Lucida Console'>(</font>sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>,new_btn<font face='Lucida Console'>)</font>;
                path <font color='#5555FF'>=</font> old_path;
                cur_dir <font color='#5555FF'>=</font> old_cur_dir;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>

                sob[cur_dir]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_checked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_dirs_click'></a>on_dirs_click</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>enter_folder</font><font face='Lucida Console'>(</font>lb_dirs[idx]<font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_files_click'></a>on_files_click</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tf_file_name.<font color='#BB00BB'>is_hidden</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                tf_file_name.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>lb_files[idx]<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_files_double_click'></a>on_files_double_click</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>on_open_click</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_cancel_click'></a>on_cancel_click</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            create_new_thread<font color='#5555FF'>&lt;</font>box_win,<font color='#5555FF'>&amp;</font>box_win::deleter_thread<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_open_click'></a>on_open_click</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lb_files.<font color='#BB00BB'>get_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> lb_files.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> tf_file_name.<font color='#BB00BB'>text</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tf_file_name.<font color='#BB00BB'>is_hidden</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font>prefix <font color='#5555FF'>+</font> path <font color='#5555FF'>+</font> lb_files[lb_files.<font color='#BB00BB'>get_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>]<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tf_file_name.<font color='#BB00BB'>text</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font>prefix <font color='#5555FF'>+</font> path <font color='#5555FF'>+</font> tf_file_name.<font color='#BB00BB'>text</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                create_new_thread<font color='#5555FF'>&lt;</font>box_win,<font color='#5555FF'>&amp;</font>box_win::deleter_thread<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_path_button_click'></a>on_path_button_click</b> <font face='Lucida Console'>(</font>
            toggle_button<font color='#5555FF'>&amp;</font> btn
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn_root.<font color='#BB00BB'>is_checked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                btn_root.<font color='#BB00BB'>set_unchecked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cur_dir <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                sob[cur_dir]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_unchecked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            std::string new_path;

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> sob.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                new_path <font color='#5555FF'>+</font><font color='#5555FF'>=</font> sob[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> directory::<font color='#BB00BB'>get_separator</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sob[i].<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>&amp;</font>btn<font face='Lucida Console'>)</font>
                <b>{</b>
                    cur_dir <font color='#5555FF'>=</font> i;
                    sob[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_checked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>break</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>path <font color='#5555FF'>!</font><font color='#5555FF'>=</font> new_path<font face='Lucida Console'>)</font>
            <b>{</b>
                path <font color='#5555FF'>=</font> new_path;
                <font color='#BB00BB'>set_dir</font><font face='Lucida Console'>(</font>prefix<font color='#5555FF'>+</font>path<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>struct</font> <b><a name='case_insensitive_compare'></a>case_insensitive_compare</b>
        <b>{</b>
            <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> a,
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> b
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                std::string::size_type i, size;
                size <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,b.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> size; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>a[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>b[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>a[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>b[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> b.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
                <font color='#0000FF'>else</font>
                    <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>;

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>bool</u></font> box_win::
        <b><a name='set_dir'></a>set_dir</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> dir
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>try</font>
            <b>{</b>
                directory <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font>dir<font face='Lucida Console'>)</font>;
                queue<font color='#5555FF'>&lt;</font>directory<font color='#5555FF'>&gt;</font>::kernel_1a_c qod;
                queue<font color='#5555FF'>&lt;</font>file<font color='#5555FF'>&gt;</font>::kernel_1a_c qof;
                queue<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font>::sort_1a_c qos;
                d.<font color='#BB00BB'>get_dirs</font><font face='Lucida Console'>(</font>qod<font face='Lucida Console'>)</font>;
                d.<font color='#BB00BB'>get_files</font><font face='Lucida Console'>(</font>qof<font face='Lucida Console'>)</font>;

                qod.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>qod.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    std::string temp <font color='#5555FF'>=</font> qod.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    qos.<font color='#BB00BB'>enqueue</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
                <b>}</b>
                qos.<font color='#BB00BB'>sort</font><font face='Lucida Console'>(</font><font color='#BB00BB'>case_insensitive_compare</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font>qos<font face='Lucida Console'>)</font>;
                qos.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                qof.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>qof.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    std::string temp <font color='#5555FF'>=</font> qof.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    qos.<font color='#BB00BB'>enqueue</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
                <b>}</b>
                qos.<font color='#BB00BB'>sort</font><font face='Lucida Console'>(</font><font color='#BB00BB'>case_insensitive_compare</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font>qos<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <b>}</b>
            <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>directory::listing_error<font color='#5555FF'>&amp;</font> <font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
            <b>}</b>
            <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>directory::dir_not_found<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> box_win::
        <b><a name='on_root_click'></a>on_root_click</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            btn_root.<font color='#BB00BB'>set_checked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cur_dir <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                sob[cur_dir]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_unchecked</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            queue<font color='#5555FF'>&lt;</font>directory<font color='#5555FF'>&gt;</font>::kernel_1a_c qod, qod2;
            queue<font color='#5555FF'>&lt;</font>file<font color='#5555FF'>&gt;</font>::kernel_1a_c qof;
            queue<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font>::sort_1a_c qos;
            <font color='#BB00BB'>get_filesystem_roots</font><font face='Lucida Console'>(</font>qod<font face='Lucida Console'>)</font>;
            path.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            cur_dir <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>qod.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
            <b>{</b>
                qod.<font color='#BB00BB'>current</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>get_files</font><font face='Lucida Console'>(</font>qof<font face='Lucida Console'>)</font>;
                qod.<font color='#BB00BB'>current</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>get_dirs</font><font face='Lucida Console'>(</font>qod2<font face='Lucida Console'>)</font>;
                prefix <font color='#5555FF'>=</font> qod.<font color='#BB00BB'>current</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>full_name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                qod2.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>qod2.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    std::string temp <font color='#5555FF'>=</font> qod2.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    qos.<font color='#BB00BB'>enqueue</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
                <b>}</b>
                qos.<font color='#BB00BB'>sort</font><font face='Lucida Console'>(</font><font color='#BB00BB'>case_insensitive_compare</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font>qos<font face='Lucida Console'>)</font>;
                qos.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                qof.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>qof.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    std::string temp <font color='#5555FF'>=</font> qof.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    qos.<font color='#BB00BB'>enqueue</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
                <b>}</b>
                qos.<font color='#BB00BB'>sort</font><font face='Lucida Console'>(</font><font color='#BB00BB'>case_insensitive_compare</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font>qos<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                prefix.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                qod.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>qod.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    std::string temp <font color='#5555FF'>=</font> qod.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>full_name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>=</font> temp.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    qos.<font color='#BB00BB'>enqueue</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
                <b>}</b>
                qos.<font color='#BB00BB'>sort</font><font face='Lucida Console'>(</font><font color='#BB00BB'>case_insensitive_compare</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                lb_dirs.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font>qos<font face='Lucida Console'>)</font>;
                qos.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                lb_files.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font>qos<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        base_window::on_close_return_code box_win::
        <b><a name='on_window_close'></a>on_window_close</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>delete</font> <font color='#0000FF'>this</font>;
            <font color='#0000FF'>return</font> CLOSE_WINDOW;
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class menu_bar
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    menu_bar::
    <b><a name='menu_bar'></a>menu_bar</b><font face='Lucida Console'>(</font>
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> : 
        drawable<font face='Lucida Console'>(</font>w, <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>, <font color='#009900'>// listen for all events
</font>        open_menu<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>adjust_position</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    menu_bar::
    ~<b><a name='menu_bar'></a>menu_bar</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b> 
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#BB00BB'>adjust_position</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>compute_menu_geometry</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='set_number_of_menus'></a>set_number_of_menus</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        menus.<font color='#BB00BB'>set_max_size</font><font face='Lucida Console'>(</font>num<font face='Lucida Console'>)</font>;
        menus.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>num<font face='Lucida Console'>)</font>;
        open_menu <font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>compute_menu_geometry</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            menus[i].menu.<font color='#BB00BB'>set_on_hide_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>menu_bar::on_popup_hide<font face='Lucida Console'>)</font>;
        <b>}</b>

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> menu_bar::
    <b><a name='number_of_menus'></a>number_of_menus</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='set_menu_name'></a>set_menu_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        <font color='#0000FF'>const</font> std::string name,
        <font color='#0000FF'><u>char</u></font> underline_ch 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_menu_name</font><font face='Lucida Console'>(</font>idx, <font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font>, underline_ch<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='set_menu_name'></a>set_menu_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        <font color='#0000FF'>const</font> std::wstring name,
        <font color='#0000FF'><u>char</u></font> underline_ch 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_menu_name</font><font face='Lucida Console'>(</font>idx, <font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font>, underline_ch<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='set_menu_name'></a>set_menu_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
        <font color='#0000FF'>const</font> dlib::ustring name,
        <font color='#0000FF'><u>char</u></font> underline_ch 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tvoid menu_bar::set_menu_name()</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_menus(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        menus[idx].name <font color='#5555FF'>=</font> name.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        menus[idx].underline_pos <font color='#5555FF'>=</font> name.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>underline_ch<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>compute_menu_geometry</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string menu_bar::
    <b><a name='menu_name'></a>menu_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_wname</font><font face='Lucida Console'>(</font>idx<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::wstring menu_bar::
    <b><a name='menu_wname'></a>menu_wname</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_uname</font><font face='Lucida Console'>(</font>idx<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> dlib::ustring menu_bar::
    <b><a name='menu_uname'></a>menu_uname</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tstd::string menu_bar::menu_name()</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_menus(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> menus[idx].name.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    popup_menu<font color='#5555FF'>&amp;</font> menu_bar::
    <b><a name='menu'></a>menu</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tpopup_menu&amp; menu_bar::menu()</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_menus(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> menus[idx].menu;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> popup_menu<font color='#5555FF'>&amp;</font> menu_bar::
    <b><a name='menu'></a>menu</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tconst popup_menu&amp; menu_bar::menu()</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_menus(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_menus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> menus[idx].menu;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_window_resized'></a>on_window_resized</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>adjust_position</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>hide_menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        rectangle <font color='#BB00BB'>area</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> opacity <font color='#5555FF'>=</font> <font color='#979000'>40</font>;
        <font color='#BB00BB'>fill_rect_with_vertical_gradient</font><font face='Lucida Console'>(</font>c, rect,<font color='#BB00BB'>rgb_alpha_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>255</font>,opacity<font face='Lucida Console'>)</font>,
                                         <font color='#BB00BB'>rgb_alpha_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font>,opacity<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// first draw the border between the menu and the rest of the window
</font>        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, 
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#979000'>100</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, 
                  <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, <font color='#979000'>255</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// now draw all the menu buttons
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,menus[i].rect, menus[i].name <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>menus[i].underline_p1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus[i].underline_p2<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, menus[i].underline_p1, menus[i].underline_p2<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>open_menu <font color='#5555FF'>=</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>fill_rect_with_vertical_gradient</font><font face='Lucida Console'>(</font>c, menus[i].bgrect,<font color='#BB00BB'>rgb_alpha_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>0</font>,<font color='#979000'>40</font><font face='Lucida Console'>)</font>,  <font color='#BB00BB'>rgb_alpha_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>40</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_window_moved'></a>on_window_moved</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>hide_menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_focus_lost'></a>on_focus_lost</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>hide_menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> btn <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>hide_menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> old_menu <font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// if a menu is currently open then save its index
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>open_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            old_menu <font color='#5555FF'>=</font> open_menu;
            <font color='#BB00BB'>hide_menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#009900'>// figure out which menu should be open if any
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>menus[i].bgrect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>old_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>show_menu</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>break</font>;
            <b>}</b>
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// if the mouse is over the menu_bar and some menu is currently open
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> open_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// if the mouse is still in the same rectangle then don't do anything
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>menus[open_menu].bgrect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// figure out which menu should be instead   
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>menus[i].bgrect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>show_menu</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>break</font>;
                    <b>}</b>
                <b>}</b>

            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::KBD_MOD_ALT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// check if the key matches any of our underlined keys
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if we have found a matching key
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_printable <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                    menus[i].underline_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>menus[i].name[menus[i].underline_pos]<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>show_menu</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                    menus[open_menu].menu.<font color='#BB00BB'>select_first_item</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>return</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>open_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> open_menu;
            <font color='#009900'>// if the submenu doesn't use this key for something then we will
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>menus[open_menu].menu.<font color='#BB00BB'>forwarded_on_keydown</font><font face='Lucida Console'>(</font>key,is_printable,state<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_LEFT<font face='Lucida Console'>)</font>
                <b>{</b>
                    i <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>i<font color='#5555FF'>+</font>menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font>menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>show_menu</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                    menus[open_menu].menu.<font color='#BB00BB'>select_first_item</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_RIGHT<font face='Lucida Console'>)</font>
                <b>{</b>
                    i <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>i<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font>menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>show_menu</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                    menus[open_menu].menu.<font color='#BB00BB'>select_first_item</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_ESC<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>hide_menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='show_menu'></a>show_menu</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
    <font face='Lucida Console'>)</font>
    <b>{</b>
        rectangle temp;

        <font color='#009900'>// menu already open so do nothing
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font><font color='#5555FF'>=</font> open_menu<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#009900'>// if a menu is currently open
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>open_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            menus[open_menu].menu.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            temp <font color='#5555FF'>=</font> menus[open_menu].bgrect;
        <b>}</b>

        <font color='#009900'>// display the new menu
</font>        open_menu <font color='#5555FF'>=</font> i;
        <font color='#0000FF'><u>long</u></font> wx, wy;
        parent.<font color='#BB00BB'>get_pos</font><font face='Lucida Console'>(</font>wx,wy<font face='Lucida Console'>)</font>;
        wx <font color='#5555FF'>+</font><font color='#5555FF'>=</font> menus[i].bgrect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        wy <font color='#5555FF'>+</font><font color='#5555FF'>=</font> menus[i].bgrect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;
        menus[i].menu.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>wx,wy<font face='Lucida Console'>)</font>;
        menus[i].menu.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>menus[i].bgrect<font color='#5555FF'>+</font>temp<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='hide_menu'></a>hide_menu</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// if a menu is currently open
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>open_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            menus[open_menu].menu.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>menus[open_menu].bgrect<font face='Lucida Console'>)</font>;
            open_menu <font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='on_popup_hide'></a>on_popup_hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// if a menu is currently open
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>open_menu <font color='#5555FF'>!</font><font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>menus[open_menu].bgrect<font face='Lucida Console'>)</font>;
            open_menu <font color='#5555FF'>=</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='compute_menu_geometry'></a>compute_menu_geometry</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'><u>long</u></font> x <font color='#5555FF'>=</font> <font color='#979000'>7</font>;
        <font color='#0000FF'><u>long</u></font> bg_x <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> menus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// compute the locations of the text rectangles
</font>            menus[i].rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
            menus[i].rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font>;
            menus[i].rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, height;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>menus[i].name,width,height<font face='Lucida Console'>)</font>;
            menus[i].rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect_width</font><font face='Lucida Console'>(</font>menus[i].rect, width<font face='Lucida Console'>)</font>;
            x <font color='#5555FF'>=</font> menus[i].rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>10</font>;

            menus[i].bgrect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            menus[i].bgrect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>bg_x<font face='Lucida Console'>)</font>;
            menus[i].bgrect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            menus[i].bgrect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>-</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
            bg_x <font color='#5555FF'>=</font> menus[i].bgrect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>menus[i].underline_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// now compute the location of the underline bar
</font>                rectangle r1 <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_rect</font><font face='Lucida Console'>(</font>
                    menus[i].rect, 
                    menus[i].name,
                    menus[i].underline_pos<font face='Lucida Console'>)</font>;

                rectangle r2 <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_rect</font><font face='Lucida Console'>(</font>
                    menus[i].rect, 
                    menus[i].name,
                    menus[i].underline_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                menus[i].underline_p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> r1.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;
                menus[i].underline_p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> r2.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;
                menus[i].underline_p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> r1.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>ascender</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font>;
                menus[i].underline_p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> r2.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>ascender</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>2</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#009900'>// there is no underline in this case
</font>                menus[i].underline_p1 <font color='#5555FF'>=</font> menus[i].underline_p2;
            <b>}</b>

        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> menu_bar::
    <b><a name='adjust_position'></a>adjust_position</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, height;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>get_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
        rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>old<font color='#5555FF'>+</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// class text_grid
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    text_grid::
    <b><a name='text_grid'></a>text_grid</b> <font face='Lucida Console'>(</font>
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> :
        scrollable_region<font face='Lucida Console'>(</font>w, KEYBOARD_EVENTS <font color='#5555FF'>|</font> MOUSE_CLICK <font color='#5555FF'>|</font> FOCUS_EVENTS <font face='Lucida Console'>)</font>,
        has_focus<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        cursor_timer<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_grid::timer_action<font face='Lucida Console'>)</font>,
        border_color_<font face='Lucida Console'>(</font><font color='#979000'>128</font>,<font color='#979000'>128</font>,<font color='#979000'>128</font><font face='Lucida Console'>)</font>
    <b>{</b>

        cursor_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_vertical_scroll_increment</font><font face='Lucida Console'>(</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_horizontal_scroll_increment</font><font face='Lucida Console'>(</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    text_grid::
    ~<b><a name='text_grid'></a>text_grid</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// Disable all further events for this drawable object.  We have to do this 
</font>        <font color='#009900'>// because we don't want draw() events coming to this object while or after 
</font>        <font color='#009900'>// it has been destructed.
</font>        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// wait for the timer to stop doing its thing
</font>        cursor_timer.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#009900'>// Tell the parent window to redraw its area that previously contained this
</font>        <font color='#009900'>// drawable object.
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_grid_size'></a>set_grid_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rows,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> cols
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        row_height.<font color='#BB00BB'>set_max_size</font><font face='Lucida Console'>(</font>rows<font face='Lucida Console'>)</font>;
        row_height.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rows<font face='Lucida Console'>)</font>;

        col_width.<font color='#BB00BB'>set_max_size</font><font face='Lucida Console'>(</font>cols<font face='Lucida Console'>)</font>;
        col_width.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>cols<font face='Lucida Console'>)</font>;

        grid.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rows,cols<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> row_height.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            row_height[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>3</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> col_width.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            col_width[i] <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>5</font>;

        <font color='#BB00BB'>compute_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>compute_bg_rects</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> text_grid::
    <b><a name='number_of_columns'></a>number_of_columns</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> text_grid::
    <b><a name='number_of_rows'></a>number_of_rows</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> grid.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>int</u></font> text_grid::
    <b><a name='next_free_user_event_number'></a>next_free_user_event_number</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rgb_pixel text_grid::
    <b><a name='border_color'></a>border_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> border_color_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_border_color'></a>set_border_color</b> <font face='Lucida Console'>(</font>
        rgb_pixel color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        border_color_ <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string text_grid::
    <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wtext</font><font face='Lucida Console'>(</font>row, col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::wstring text_grid::
    <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>utext</font><font face='Lucida Console'>(</font>row, col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> dlib::ustring text_grid::
    <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tconst std::string text_grid::text(row,col)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> grid[row][col].text.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>row, col, <font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>row, col, <font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> str
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tvoid text_grid::set_text(row,col)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        grid[row][col].text <font color='#5555FF'>=</font> str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel text_grid::
    <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tconst rgb_pixel text_grid::text_color(row,col)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> grid[row][col].text_color;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tvoid text_grid::set_text_color(row,col,color)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        grid[row][col].text_color <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel text_grid::
    <b><a name='background_color'></a>background_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tconst rgb_pixel text_grid::background_color(row,col,color)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> grid[row][col].bg_color;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_background_color'></a>set_background_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tvoid text_grid::set_background_color(row,col,color)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        grid[row][col].bg_color <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_bg_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> text_grid::
    <b><a name='is_editable'></a>is_editable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tbool text_grid::is_editable(row,col)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> grid[row][col].is_editable;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_editable'></a>set_editable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'><u>bool</u></font> editable
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tvoid text_grid::set_editable(row,col,editable)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\teditable:         </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> editable 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        grid[row][col].is_editable <font color='#5555FF'>=</font> editable;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> active_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>row<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> active_col <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>drop_input_focus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_column_width'></a>set_column_width</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> col <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                      "<font color='#CC0000'>\tvoid text_grid::set_column_width(col,width)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tcol:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_columns(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_columns</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\twidth:            </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> width 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        col_width[col] <font color='#5555FF'>=</font> width;
        <font color='#BB00BB'>compute_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>compute_bg_rects</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='set_row_height'></a>set_row_height</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> row <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tvoid text_grid::set_row_height(row,height)</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\trow:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_rows(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_rows</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\theight:           </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> height 
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        row_height[row] <font color='#5555FF'>=</font> height;
        <font color='#BB00BB'>compute_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>compute_bg_rects</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        scrollable_region::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>drop_input_focus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        scrollable_region::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>drop_input_focus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// ignore this user event if it isn't for us
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num <font color='#5555FF'>!</font><font color='#5555FF'>=</font> scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>recent_cursor_move <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            show_cursor <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>show_cursor;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        recent_cursor_move <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='timer_action'></a>timer_action</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='compute_bg_rects'></a>compute_bg_rects</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// loop over each element in the grid and figure out what its rectangle should be
</font>        <font color='#009900'>// with respect to the total_rect()
</font>        point p1, p2;
        p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> row <font color='#5555FF'>=</font> <font color='#979000'>0</font>; row <font color='#5555FF'>&lt;</font> grid.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>row<font face='Lucida Console'>)</font>
        <b>{</b>
            p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> row_height[row]<font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> col <font color='#5555FF'>=</font> <font color='#979000'>0</font>; col <font color='#5555FF'>&lt;</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>col<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if this is the last box in this row make it super wide so that it always
</font>                <font color='#009900'>// goes to the end of the widget
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>col<font color='#5555FF'>+</font><font color='#979000'>1</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>1000000</font>;
                <font color='#0000FF'>else</font>
                    p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> col_width[col]<font color='#5555FF'>-</font><font color='#979000'>1</font>;

                <font color='#009900'>// at this point p1 is the upper left corner of this box and p2 is the 
</font>                <font color='#009900'>// lower right corner of the box;
</font>                rectangle <font color='#BB00BB'>bg_rect</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font>;
                bg_rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p2;

                grid[row][col].bg_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font>bg_rect, <font color='#5555FF'>-</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>-</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


                p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> col_width[col];
            <b>}</b>
            p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>+</font> row_height[row];
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='compute_total_rect'></a>compute_total_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>grid.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width <font color='#5555FF'>=</font> col_width.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height <font color='#5555FF'>=</font> row_height.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> col_width.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                width <font color='#5555FF'>+</font><font color='#5555FF'>=</font> col_width[i];
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> row_height.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                height <font color='#5555FF'>+</font><font color='#5555FF'>=</font> row_height[i];

            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,          
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// ignore this event if we are disabled or hidden
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_printable<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if the user hit the tab key then jump to the next box
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\t</font>'<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>active_col<font color='#5555FF'>+</font><font color='#979000'>1</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>active_row<font color='#5555FF'>+</font><font color='#979000'>1</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>else</font>
                            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row<font color='#5555FF'>+</font><font color='#979000'>1</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col<font color='#5555FF'>+</font><font color='#979000'>1</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// ignore the enter key
</font>                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>grid[active_row][active_col].is_editable<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// insert the key the user pressed into the string
</font>                    grid[active_row][active_col].text.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>cursor_pos,<font color='#979000'>1</font>,<font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,cursor_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::KBD_MOD_CONTROL<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_LEFT<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col<font color='#5555FF'>-</font><font color='#979000'>1</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_RIGHT<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col<font color='#5555FF'>+</font><font color='#979000'>1</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_UP<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row<font color='#5555FF'>-</font><font color='#979000'>1</font>,active_col,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DOWN<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row<font color='#5555FF'>+</font><font color='#979000'>1</font>,active_col,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_END<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,grid[active_row][active_col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_HOME<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_LEFT<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_RIGHT<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,cursor_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_UP<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row<font color='#5555FF'>-</font><font color='#979000'>1</font>,active_col,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DOWN<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row<font color='#5555FF'>+</font><font color='#979000'>1</font>,active_col,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_END<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,grid[active_row][active_col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_HOME<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_BACKSPACE<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> grid[active_row][active_col].is_editable<font face='Lucida Console'>)</font>
                    <b>{</b>
                        grid[active_row][active_col].text.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>
                            grid[active_row][active_col].text.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font>,
                            grid[active_row][active_col].text.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DELETE<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>&lt;</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>grid[active_row][active_col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                        grid[active_row][active_col].is_editable<font face='Lucida Console'>)</font>
                    <b>{</b>
                        grid[active_row][active_col].text.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>
                            grid[active_row][active_col].text.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>active_row,active_col,cursor_pos<font face='Lucida Console'>)</font>;

                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
        <b>}</b> <font color='#009900'>// if (has_focus)
</font>    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> is_double_click
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>on_mouse_down</font><font face='Lucida Console'>(</font>btn, state, x, y, is_double_click<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// figure out which box this click landed in
</font>            rectangle hit;

            <font color='#009900'>// find which column we hit
</font>            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'><u>long</u></font> box_x <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> col_width.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>box_x <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> x <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>x <font color='#5555FF'>&lt;</font> box_x<font color='#5555FF'>+</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>col_width[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font face='Lucida Console'>(</font>i<font color='#5555FF'>+</font><font color='#979000'>1</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> col_width.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    col <font color='#5555FF'>=</font> i;
                    hit.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>box_x<font face='Lucida Console'>)</font>;
                    hit.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>box_x<font color='#5555FF'>+</font>col_width[i]<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>break</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    box_x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> col_width[i]<font color='#5555FF'>+</font><font color='#979000'>1</font>;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>// find which row we hit
</font>            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'><u>long</u></font> box_y <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> row_height.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>box_y <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> y <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> y <font color='#5555FF'>&lt;</font> box_y<font color='#5555FF'>+</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>row_height[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    row <font color='#5555FF'>=</font> i;
                    hit.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>box_y<font face='Lucida Console'>)</font>;
                    hit.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>box_y<font color='#5555FF'>+</font>row_height[i]<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>break</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    box_y <font color='#5555FF'>+</font><font color='#5555FF'>=</font> row_height[i]<font color='#5555FF'>+</font><font color='#979000'>1</font>;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>// if we hit a box
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>hit.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>row, 
                            col,
                            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font>, grid[row][col].text, x, y, grid[row][col].first<font face='Lucida Console'>)</font>
                <font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#BB00BB'>drop_input_focus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#BB00BB'>drop_input_focus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>on_mouse_up</font><font face='Lucida Console'>(</font>btn, state, x, y<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='on_focus_lost'></a>on_focus_lost</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>drop_input_focus</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>draw</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        rectangle area <font color='#5555FF'>=</font> c.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>fill_rect</font><font face='Lucida Console'>(</font>c, area, <font color='#979000'>255</font><font face='Lucida Console'>)</font>; 

        <font color='#009900'>// don't do anything if the grid is empty
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>grid.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#009900'>// draw all the vertical lines
</font>        point p1, p2;
        p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> col_width.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> col_width[i];
            p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> col_width[i];
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,p1,p2,border_color_,area<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,p1,p2,<font color='#979000'>128</font>,area<font face='Lucida Console'>)</font>;
            p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
        <b>}</b>

        <font color='#009900'>// draw all the horizontal lines
</font>        p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> row_height.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> row_height[i];
            p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> row_height[i];
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,p1,p2,border_color_,area<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,p1,p2,<font color='#979000'>128</font>,area<font face='Lucida Console'>)</font>;
            p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
        <b>}</b>

        <font color='#009900'>// draw the backgrounds and text for each box
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> row <font color='#5555FF'>=</font> <font color='#979000'>0</font>; row <font color='#5555FF'>&lt;</font> grid.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>row<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> col <font color='#5555FF'>=</font> <font color='#979000'>0</font>; col <font color='#5555FF'>&lt;</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>col<font face='Lucida Console'>)</font>
            <b>{</b>
                rectangle <font color='#BB00BB'>bg_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_bg_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                rectangle <font color='#BB00BB'>text_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>fill_rect</font><font face='Lucida Console'>(</font>c,bg_rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font>,grid[row][col].bg_color<font face='Lucida Console'>)</font>;

                    mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,
                                       text_rect, 
                                       grid[row][col].text, 
                                       grid[row][col].text_color, 
                                       grid[row][col].first, 
                                       std::string::npos, 
                                       area<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,
                                       text_rect, 
                                       grid[row][col].text, 
                                       <font color='#979000'>128</font>, 
                                       grid[row][col].first, 
                                       std::string::npos, 
                                       area<font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#009900'>// if this box has input focus then draw it with a cursor
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> active_col <font color='#5555FF'>=</font><font color='#5555FF'>=</font> col <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> active_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> row <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> show_cursor<font face='Lucida Console'>)</font>
                <b>{</b>
                    rectangle cursor_rect <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_rect</font><font face='Lucida Console'>(</font>text_rect,
                                                                       grid[row][col].text,
                                                                       cursor_pos,
                                                                       grid[row][col].first<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c,cursor_rect,<font color='#979000'>0</font>,area<font face='Lucida Console'>)</font>;
                <b>}</b>

            <b>}</b>
        <b>}</b>


    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle text_grid::
    <b><a name='get_text_rect'></a>get_text_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        rectangle <font color='#BB00BB'>bg_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_bg_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>long</u></font> padding <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>bg_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>bg_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font><font color='#979000'>2</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>padding <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            padding <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        bg_rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>bg_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>padding<font face='Lucida Console'>)</font>;
        bg_rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>bg_rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>padding<font face='Lucida Console'>)</font>;
        bg_rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>bg_rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>padding<font face='Lucida Console'>)</font>;
        bg_rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>bg_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>padding<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> bg_rect;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle text_grid::
    <b><a name='get_bg_rect'></a>get_bg_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font>grid[row][col].bg_rect, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='drop_input_focus'></a>drop_input_focus</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus<font face='Lucida Console'>)</font>
        <b>{</b>
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            show_cursor <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            cursor_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_grid::
    <b><a name='move_cursor'></a>move_cursor</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> row,
        <font color='#0000FF'><u>long</u></font> col,
        <font color='#0000FF'><u>long</u></font> new_cursor_pos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// don't do anything if the grid is empty
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>grid.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>row <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            row <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>row <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            row <font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>col <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            col <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>col <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            col <font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_cursor_pos <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>col <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                new_cursor_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> 
            <b>{</b>
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>col;
                new_cursor_pos <font color='#5555FF'>=</font> grid[row][col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_cursor_pos <font color='#5555FF'>&gt;</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>grid[row][col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>col<font color='#5555FF'>+</font><font color='#979000'>1</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> grid.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                new_cursor_pos <font color='#5555FF'>=</font> grid[row][col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> 
            <b>{</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>col;
                new_cursor_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// if some other box had the input focus then redraw it
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>active_row <font color='#5555FF'>!</font><font color='#5555FF'>=</font> row <font color='#5555FF'>|</font><font color='#5555FF'>|</font> active_col <font color='#5555FF'>!</font><font color='#5555FF'>=</font> col <font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            cursor_timer.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        has_focus <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        recent_cursor_move <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        show_cursor <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        active_row <font color='#5555FF'>=</font> row;
        active_col <font color='#5555FF'>=</font> col;
        cursor_pos <font color='#5555FF'>=</font> new_cursor_pos;

        <font color='#009900'>// adjust the first character to draw so that the string is displayed well
</font>        rectangle <font color='#BB00BB'>text_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font>active_row,active_col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        rectangle cursor_rect <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_rect</font><font face='Lucida Console'>(</font>text_rect,
                                                           grid[row][col].text,
                                                           cursor_pos,
                                                           grid[row][col].first<font face='Lucida Console'>)</font>;

        <font color='#009900'>// if the cursor rect is too far to the left of the string
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>&lt;</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>grid[row][col].first<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>&gt;</font> <font color='#979000'>5</font><font face='Lucida Console'>)</font>
            <b>{</b>
                grid[row][col].first <font color='#5555FF'>=</font> cursor_pos <font color='#5555FF'>-</font> <font color='#979000'>5</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                grid[row][col].first <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <b>}</b>
        <b>}</b>
        <font color='#009900'>// if the cursor rect is too far to the right of the string
</font>        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> text_rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> distance <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>cursor_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> text_rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> text_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>3</font>;
            <font color='#009900'>// find the letter that is distance pixels from the start of the string
</font>            <font color='#0000FF'><u>long</u></font> sum <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> grid[row][col].first; i <font color='#5555FF'>&lt;</font> grid[row][col].text.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>[grid[row][col].text[i]].<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>sum <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> distance<font face='Lucida Console'>)</font>
                <b>{</b>
                    grid[row][col].first <font color='#5555FF'>=</font> i;
                    <font color='#0000FF'>break</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_bg_rect</font><font face='Lucida Console'>(</font>row,col<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// redraw our box
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>text_rect<font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// text_field object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle text_box::
    <b><a name='get_text_rect'></a>get_text_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> padding <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;

        rectangle text_rect;
        text_rect.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>padding<font face='Lucida Console'>)</font>;
        text_rect.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>padding<font face='Lucida Console'>)</font>;
        text_rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>padding<font face='Lucida Console'>)</font>;
        text_rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>padding<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> text_rect;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_cut'></a>on_cut</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>on_copy</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>on_delete_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_copy'></a>on_copy</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>put_on_clipboard</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_start, highlight_end<font color='#5555FF'>-</font>highlight_start<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_paste'></a>on_paste</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        ustring temp_str;
        <font color='#BB00BB'>get_from_clipboard</font><font face='Lucida Console'>(</font>temp_str<font face='Lucida Console'>)</font>;


        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
        <b>{</b>
            text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,highlight_start<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> temp_str <font color='#5555FF'>+</font>
                text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_end<font color='#5555FF'>+</font><font color='#979000'>1</font>,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>highlight_end<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font color='#5555FF'>+</font>temp_str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> temp_str <font color='#5555FF'>+</font>
                text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>cursor_pos,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cursor_pos<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>+</font>temp_str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp_str.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_select_all'></a>on_select_all</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        highlight_end <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>on_text_is_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_delete_selected'></a>on_delete_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
        <b>{</b>
            text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>highlight_start,highlight_end<font color='#5555FF'>-</font>highlight_start<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font face='Lucida Console'>)</font>;
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;

            <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_text_is_selected'></a>on_text_is_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>enable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>enable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>enable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_no_text_selected'></a>on_no_text_selected</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>disable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>disable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>disable_menu_item</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        scrollable_region::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        t.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        right_click_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        scrollable_region::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        t.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='adjust_total_rect'></a>adjust_total_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> padding <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> text_width;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> text_height;

        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>text_, text_width, text_height<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>text_width <font color='#5555FF'>+</font> padding<font color='#5555FF'>*</font><font color='#979000'>2</font>, text_height <font color='#5555FF'>+</font> padding<font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>draw</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;
       
        <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_text_box</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, enabled, <font color='#5555FF'>*</font>mfont, text_, 
                             <font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font>cursor_rect, origin<font face='Lucida Console'>)</font>, 
                               text_color_, bg_color_, has_focus, cursor_visible, highlight_start,
                               highlight_end<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        text_ <font color='#5555FF'>=</font> text.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                
        <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string text_box::
    <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        std::string temp <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wtext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring text_box::
    <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        std::wstring temp <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>utext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>
    
    <font color='#0000FF'>const</font> dlib::ustring text_box::
    <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the dlib::ustring implementation.
</font>        dlib::ustring temp <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
    <font face='Lucida Console'>)</font>
    <b>{</b>        
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        scrollable_region::<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_background_color'></a>set_background_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        bg_color_ <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel text_box::
    <b><a name='background_color'></a>background_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> bg_color_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rgb_pixel color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        text_color_ <font color='#5555FF'>=</font> color;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rgb_pixel text_box::
    <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> text_color_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>has_focus<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>=</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                    shift_pos <font color='#5555FF'>=</font> highlight_end <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                <font color='#0000FF'>else</font>
                    shift_pos <font color='#5555FF'>=</font> highlight_start;
            <b>}</b>

            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,text_,x,y<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,
        <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font>
            shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> double_clicked 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> btn <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>base_window::LEFT<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            has_focus <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            t.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>double_clicked<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// highlight the double clicked word
</font>                string::size_type first, last;
                <font color='#0000FF'>const</font> ustring ustr <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf8_to_utf32</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'> \t\n</font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                first <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font>.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>ustr.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                last <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>ustr.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,cursor_pos<font face='Lucida Console'>)</font>;
                <font color='#0000FF'><u>long</u></font> f <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>first<font face='Lucida Console'>)</font>;
                <font color='#0000FF'><u>long</u></font> l <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>last<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>first <font color='#5555FF'>=</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
                    f <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>last <font color='#5555FF'>=</font><font color='#5555FF'>=</font> string::npos<font face='Lucida Console'>)</font>
                    l <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>f;
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>l;

                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>l<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                highlight_start <font color='#5555FF'>=</font> f;
                highlight_end <font color='#5555FF'>=</font> l;
                <font color='#BB00BB'>on_text_is_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::SHIFT<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>=</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_end <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                        <font color='#0000FF'>else</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_start;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        shift_pos <font color='#5555FF'>=</font> cursor_pos;
                    <b>}</b>
                <b>}</b>

                <font color='#0000FF'><u>bool</u></font> at_end <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> cursor_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    at_end <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> old_pos <font color='#5555FF'>=</font> cursor_pos;

                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,text_,x,y<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;

                shift_pos <font color='#5555FF'>=</font> cursor_pos;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>at_end <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> cursor_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> old_pos<font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            t.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>focus_lost_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>focus_lost_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            has_focus <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// If the right click menu is up then we don't want to do anything with
</font>        <font color='#009900'>// the keyboard ourselves.  Let the popup menu use the keyboard for now.
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>right_click_menu.<font color='#BB00BB'>popup_menu_visible</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> ustring space_str <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf8_to_utf32</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'> \t\n</font>"<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>bool</u></font> shift <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::KBD_MOD_SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>bool</u></font> ctrl <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::KBD_MOD_CONTROL<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> is_printable <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>=</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_end <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
                        <font color='#0000FF'>else</font>
                            shift_pos <font color='#5555FF'>=</font> highlight_start;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        shift_pos <font color='#5555FF'>=</font> cursor_pos;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                shift_pos <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_LEFT<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// find the first non-whitespace to our left
</font>                        std::string::size_type pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_last_not_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                        <b>{</b>
                            pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,pos<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>else</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <b>}</b>
                        <font color='#0000FF'>else</font>
                        <b>{</b>
                            new_pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <b>}</b>
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        new_pos <font color='#5555FF'>=</font> cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <b>}</b>

                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>

            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_RIGHT<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_pos;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// find the first non-whitespace to our left
</font>                        std::string::size_type pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_not_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                        <b>{</b>
                            pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>space_str.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,pos<font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> std::string::npos<font face='Lucida Console'>)</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>else</font>
                                new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>else</font>
                        <b>{</b>
                            new_pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        new_pos <font color='#5555FF'>=</font> cursor_pos<font color='#5555FF'>+</font><font color='#979000'>1</font>;
                    <b>}</b>

                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>new_pos<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_UP<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#009900'>// move the cursor so the position that is just a few pixels above 
</font>                    <font color='#009900'>// the current cursor_rect
</font>                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font>
                            <font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, text_, cursor_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>origin.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, 
                            cursor_rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>origin.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <b>}</b>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DOWN<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#009900'>// move the cursor so the position that is just a few pixels above 
</font>                    <font color='#009900'>// the current cursor_rect
</font>                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_pos</font><font face='Lucida Console'>(</font>
                            <font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, text_, cursor_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>origin.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, 
                            cursor_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>origin.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_printable<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>a</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_select_all</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>c</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_copy</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>v</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_paste</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>x</font>'<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>on_cut</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>else</font> 
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                    <b>{</b>
                        text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,highlight_start<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>unichar<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
                            text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_end<font color='#5555FF'>+</font><font color='#979000'>1</font>,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>highlight_end<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                        <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                        highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                        <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>unichar<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
                            text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>cursor_pos,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cursor_pos<font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <b>}</b>

                    <font color='#009900'>// send out the text modified event
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                <b>}</b>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enter_key_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>enter_key_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_BACKSPACE<font face='Lucida Console'>)</font>
            <b>{</b>                
                <font color='#009900'>// if something is highlighted then delete that
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>on_delete_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                    <font color='#009900'>// send out the text modified event
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#009900'>// do this just so it repaints itself right
</font>                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font face='Lucida Console'>)</font>;
                <b>}</b>

            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DELETE<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if something is highlighted then delete that
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>on_delete_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>cursor_pos,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                    <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#009900'>// send out the text modified event
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#009900'>// do this just so it repaints itself right
</font>                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font face='Lucida Console'>)</font>;
                <b>}</b>

            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_HOME<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// find the start of the current line
</font>                    ustring::size_type pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_last_of</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>\n</font>',cursor_pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> ustring::npos<font face='Lucida Console'>)</font>
                        pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    <font color='#0000FF'>else</font>
                        pos <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <b>}</b>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_END<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ctrl<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <b>{</b>
                    ustring::size_type pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>find_first_of</font><font face='Lucida Console'>(</font>'<font color='#FF0000'>\n</font>',cursor_pos<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> ustring::npos<font face='Lucida Console'>)</font>
                        pos <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                    <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                    <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_PAGE_DOWN <font color='#5555FF'>|</font><font color='#5555FF'>|</font> key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_PAGE_UP<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> jump_size <font color='#5555FF'>=</font> <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> 
                    std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>3</font>, <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;

                <font color='#009900'>// if we are supposed to page up then just jump in the other direction
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_PAGE_UP<font face='Lucida Console'>)</font>
                    jump_size <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>jump_size;

                <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>, jump_size <font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
            <b>}</b>

            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            recent_movement <font color='#5555FF'>=</font> <font color='#979000'>true</font>;

        <b>}</b>
    <b>}</b>

<font color='#009900'>// ---------------------------------------------------------------------------------------- 
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='on_string_put'></a>on_string_put</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring <font color='#5555FF'>&amp;</font>str
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>has_focus <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            ustring ustr <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> highlight_end<font face='Lucida Console'>)</font>
            <b>{</b>
                text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,highlight_start<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> ustr <font color='#5555FF'>+</font>
                    text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>highlight_end<font color='#5555FF'>+</font><font color='#979000'>1</font>,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>highlight_end<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>highlight_start<font color='#5555FF'>+</font>ustr.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
                <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                text_ <font color='#5555FF'>=</font> text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,cursor_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> ustr <font color='#5555FF'>+</font>
                    text_.<font color='#BB00BB'>substr</font><font face='Lucida Console'>(</font>cursor_pos,text_.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cursor_pos<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>move_cursor</font><font face='Lucida Console'>(</font>cursor_pos<font color='#5555FF'>+</font>ustr.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>


            <font color='#009900'>// send out the text modified event
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>text_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>text_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>
    
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> text_box::
    <b><a name='move_cursor'></a>move_cursor</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> pos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> old_cursor_pos <font color='#5555FF'>=</font> cursor_pos;



        <font color='#009900'>// figure out where the cursor is supposed to be
</font>        cursor_rect <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, text_, pos<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        cursor_pos <font color='#5555FF'>=</font> pos;     


        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> padding <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;

        <font color='#009900'>// find the delta between the cursor rect and the corner of the total rect 
</font>        point delta <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>cursor_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, cursor_rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// now scroll us so that we can see the current cursor 
</font>        <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>cursor_rect, cursor_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> padding <font color='#5555FF'>+</font> <font color='#979000'>6</font>, cursor_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// adjust the cursor_rect so that it is relative to the total_rect
</font>        cursor_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font>cursor_rect, <font color='#5555FF'>-</font>origin<font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>set_im_pos</font><font face='Lucida Console'>(</font>cursor_rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, cursor_rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>old_cursor_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> cursor_pos<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
            <b>{</b>
                highlight_start <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>shift_pos,cursor_pos<font face='Lucida Console'>)</font>;
                highlight_end <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>shift_pos,cursor_pos<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlight_start <font color='#5555FF'>&gt;</font> highlight_end<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>on_no_text_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>on_text_is_selected</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            recent_movement <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>shift_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            highlight_start <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            highlight_end <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//       perspective_display member functions
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    perspective_display::
    <b><a name='perspective_display'></a>perspective_display</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> : 
        drawable<font face='Lucida Console'>(</font>w,MOUSE_MOVE<font color='#5555FF'>|</font>MOUSE_CLICK<font color='#5555FF'>|</font>MOUSE_WHEEL<font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>clear_overlay</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    perspective_display::
    ~<b><a name='perspective_display'></a>perspective_display</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,height<font face='Lucida Console'>)</font>;
        tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_up_direction</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>old<font color='#5555FF'>+</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_line<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>overlay.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;
        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_lines.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>overlay_lines.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            sum_pts <font color='#5555FF'>+</font><font color='#5555FF'>=</font> overlay[i].p1;
            sum_pts <font color='#5555FF'>+</font><font color='#5555FF'>=</font> overlay[i].p2;
            max_pts.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p1.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p2.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>max_pts,
            sum_pts<font color='#5555FF'>/</font><font face='Lucida Console'>(</font>overlay_lines.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font>overlay_dots.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_dot<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>overlay.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            overlay_dots.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>overlay[i]<font face='Lucida Console'>)</font>;

            sum_pts <font color='#5555FF'>+</font><font color='#5555FF'>=</font> overlay[i].p;
            max_pts.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            max_pts.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>overlay[i].p.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pts.<font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>max_pts,
            sum_pts<font color='#5555FF'>/</font><font face='Lucida Console'>(</font>overlay_lines.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font>overlay_dots.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='clear_overlay'></a>clear_overlay</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        overlay_dots.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        overlay_lines.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        sum_pts <font color='#5555FF'>=</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        max_pts <font color='#5555FF'>=</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            <font color='#5555FF'>-</font>std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            <font color='#5555FF'>-</font>std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='set_dot_double_clicked_handler'></a>set_dot_double_clicked_handler</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        dot_clicked_event_handler <font color='#5555FF'>=</font> event_handler_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>depth.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>c.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> depth.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>c.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            depth.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>c.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, c.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>assign_all_pixels</font><font face='Lucida Console'>(</font>depth, std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>fill_rect</font><font face='Lucida Console'>(</font>c, area, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_lines.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>tform</font><font face='Lucida Console'>(</font>overlay_lines[i].p1<font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                         <font color='#BB00BB'>tform</font><font face='Lucida Console'>(</font>overlay_lines[i].p2<font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, 
                         overlay_lines[i].color, 
                         area<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_dots.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> scale, distance;
            point p <font color='#5555FF'>=</font> <font color='#BB00BB'>tform</font><font face='Lucida Console'>(</font>overlay_dots[i].p, scale, distance<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> depth[p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>c.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>][p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>c.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>&gt;</font> distance<font face='Lucida Console'>)</font>
            <b>{</b>
                depth[p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>c.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>][p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>c.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> distance;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>c[p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>c.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>][p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>c.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>], overlay_dots[i].color<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='on_wheel_up'></a>on_wheel_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <font color='#009900'>//state
</font>    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>enabled<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> alpha <font color='#5555FF'>=</font> <font color='#979000'>0.10</font>;
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> delta <font color='#5555FF'>=</font> alpha<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>
            tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> delta,
            tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_up_direction</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='on_wheel_down'></a>on_wheel_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <font color='#009900'>//state
</font>    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>enabled<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> alpha <font color='#5555FF'>=</font> <font color='#979000'>0.10</font>;
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> delta <font color='#5555FF'>=</font> alpha<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>
            tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> delta,
            tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_up_direction</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>, <font color='#009900'>//state
</font>        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> is_double_click
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>|</font><font color='#5555FF'>|</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT<font face='Lucida Console'>)</font>
        <b>{</b>
            last <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_double_click <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> overlay_dots.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> best_idx <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>const</font> dpoint <font color='#BB00BB'>pp</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_dots.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                dpoint p <font color='#5555FF'>=</font> <font color='#BB00BB'>tform</font><font face='Lucida Console'>(</font>overlay_dots[i].p<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'><u>double</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>length_squared</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>pp<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                <b>{</b>
                    best_dist <font color='#5555FF'>=</font> dist;
                    best_idx <font color='#5555FF'>=</font> i;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dot_clicked_event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>dot_clicked_event_handler</font><font face='Lucida Console'>(</font>overlay_dots[best_idx].p<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> perspective_display::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>enabled <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>cur</font><font face='Lucida Console'>(</font>x, y<font face='Lucida Console'>)</font>;
            dpoint delta <font color='#5555FF'>=</font> last<font color='#5555FF'>-</font>cur;
            last <font color='#5555FF'>=</font> cur;

            <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> radius <font color='#5555FF'>=</font> tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            delta <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>2</font><font color='#5555FF'>*</font>pi<font color='#5555FF'>*</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>radius<font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>600.0</font>;
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> tangent_x <font color='#5555FF'>=</font> tform.<font color='#BB00BB'>get_camera_up_direction</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>cross</font><font face='Lucida Console'>(</font>radius<font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> tangent_y <font color='#5555FF'>=</font> radius.<font color='#BB00BB'>cross</font><font face='Lucida Console'>(</font>tangent_x<font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> new_pos <font color='#5555FF'>=</font> tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> tangent_x<font color='#5555FF'>*</font>delta.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> tangent_y<font color='#5555FF'>*</font><font color='#5555FF'>-</font>delta.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 

            <font color='#009900'>// now make it have the correct radius relative to the looking at point.
</font>            new_pos <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>new_pos<font color='#5555FF'>-</font>tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>radius<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>new_pos,
                tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                tangent_y,
                tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>base_window::LEFT<font color='#5555FF'>|</font>base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
            state <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>cur</font><font face='Lucida Console'>(</font>x, y<font face='Lucida Console'>)</font>;
            dpoint delta <font color='#5555FF'>=</font> last<font color='#5555FF'>-</font>cur;
            last <font color='#5555FF'>=</font> cur;

            <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> radius <font color='#5555FF'>=</font> tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            delta <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>2</font><font color='#5555FF'>*</font>pi<font color='#5555FF'>*</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>radius<font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>600.0</font>;
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> tangent_x <font color='#5555FF'>=</font> tform.<font color='#BB00BB'>get_camera_up_direction</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>cross</font><font face='Lucida Console'>(</font>radius<font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> tangent_y <font color='#5555FF'>=</font> radius.<font color='#BB00BB'>cross</font><font face='Lucida Console'>(</font>tangent_x<font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> offset <font color='#5555FF'>=</font> tangent_x<font color='#5555FF'>*</font>delta.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> tangent_y<font color='#5555FF'>*</font><font color='#5555FF'>-</font>delta.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 


            tform <font color='#5555FF'>=</font> <font color='#BB00BB'>camera_transform</font><font face='Lucida Console'>(</font>
                tform.<font color='#BB00BB'>get_camera_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset,
                tform.<font color='#BB00BB'>get_camera_looking_at</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>offset,
                tform.<font color='#BB00BB'>get_camera_up_direction</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                tform.<font color='#BB00BB'>get_camera_field_of_view</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//       image_display member functions
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>class</font> <b><a name='image_display_functor'></a>image_display_functor</b>
        <b>{</b>
            <font color='#0000FF'>const</font> std::string str;
            <font color='#0000FF'>const</font> member_function_pointer<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font color='#5555FF'>&gt;</font> mfp;
        <font color='#0000FF'>public</font>:
            <b><a name='image_display_functor'></a>image_display_functor</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> str_,
                <font color='#0000FF'>const</font> member_function_pointer<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> mfp_
            <font face='Lucida Console'>)</font> : str<font face='Lucida Console'>(</font>str_<font face='Lucida Console'>)</font>,
                mfp<font face='Lucida Console'>(</font>mfp_<font face='Lucida Console'>)</font>
            <b>{</b><b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#BB00BB'>mfp</font><font face='Lucida Console'>(</font>str<font face='Lucida Console'>)</font>; <b>}</b>
        <b>}</b>;
    <b>}</b>

    image_display::
    <b><a name='image_display'></a>image_display</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font>: 
        scrollable_region<font face='Lucida Console'>(</font>w,KEYBOARD_EVENTS<font face='Lucida Console'>)</font>,
        zoom_in_scale<font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        zoom_out_scale<font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        drawing_rect<font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font>,
        rect_is_selected<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        selected_rect<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        default_rect_color<font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>,
        parts_menu<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        part_width<font face='Lucida Console'>(</font><font color='#979000'>15</font><font face='Lucida Console'>)</font>, <font color='#009900'>// width part circles are drawn on the screen
</font>        overlay_editing_enabled<font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font>,
        highlight_timer<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>, <font color='#5555FF'>&amp;</font>image_display::timer_event_unhighlight_rect<font face='Lucida Console'>)</font>,
        highlighted_rect<font face='Lucida Console'>(</font>std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font>::max<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
    <b>{</b> 
        <font color='#BB00BB'>enable_mouse_drag</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        highlight_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>250</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_horizontal_scroll_increment</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_vertical_scroll_increment</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_horizontal_mouse_wheel_scroll_increment</font><font face='Lucida Console'>(</font><font color='#979000'>30</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>set_vertical_mouse_wheel_scroll_increment</font><font face='Lucida Console'>(</font><font color='#979000'>30</font><font face='Lucida Console'>)</font>;

        parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;


        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_part_add'></a>on_part_add</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> part_name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>rect_is_selected<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>const</font> point loc <font color='#5555FF'>=</font> last_right_click_pos;
        
        <font color='#009900'>// Transform loc from gui window space into the space used by the overlay
</font>        <font color='#009900'>// rectangles (i.e. relative to the raw image)
</font>        <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        point c1 <font color='#5555FF'>=</font> loc <font color='#5555FF'>-</font> origin;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            c1 <font color='#5555FF'>=</font> c1<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_in_scale;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            c1 <font color='#5555FF'>=</font> c1<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_out_scale;
        <b>}</b>

        overlay_rects[selected_rect].parts[part_name] <font color='#5555FF'>=</font> c1;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    image_display::
    ~<b><a name='image_display'></a>image_display</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        highlight_timer.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle image_display::
    <b><a name='get_image_display_rect'></a>get_image_display_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>, img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>-</font><font color='#979000'>1</font>, img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>, img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale<font color='#5555FF'>-</font><font color='#979000'>1</font>, img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>return</font> dlib::<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>;

        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> overlay_line<font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_lines.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>;

        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font><font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>overlay.p1, overlay.p2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> overlay_circle<font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_circles.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>;

        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_rects.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>overlay_rects.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_line<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_lines.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>overlay_lines.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#009900'>// push this new overlay into our overlay vector
</font>        overlay_circles.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>overlay_circles.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// make the parent window redraw us now that we changed the overlay
</font>        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='clear_overlay'></a>clear_overlay</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        overlay_rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        overlay_lines.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        overlay_circles.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle image_display::
    <b><a name='get_rect_on_screen'></a>get_rect_on_screen</b> <font face='Lucida Console'>(</font>
        rectangle orect 
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        orect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>   <font color='#5555FF'>=</font> orect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>/</font>zoom_out_scale;
        orect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>    <font color='#5555FF'>=</font> orect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>/</font>zoom_out_scale;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// make it so the box surrounds the pixels when we zoom in.
</font>            orect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>orect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>/</font>zoom_out_scale;
            orect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>orect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>/</font>zoom_out_scale;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            orect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>=</font> orect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>/</font>zoom_out_scale;
            orect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> orect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font color='#5555FF'>/</font>zoom_out_scale;
        <b>}</b>

        <font color='#0000FF'>return</font> <font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font>orect, origin<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle image_display::
    <b><a name='get_rect_on_screen'></a>get_rect_on_screen</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font>overlay_rects[idx].rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>draw</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;

        rectangle area <font color='#5555FF'>=</font> <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        
        <font color='#009900'>// draw the image on the screen
</font>        <font color='#0000FF'>const</font> rectangle img_area <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> row <font color='#5555FF'>=</font> img_area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; row <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> img_area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>row<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> col <font color='#5555FF'>=</font> img_area.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; col <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> img_area.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>col<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>c[row<font color='#5555FF'>-</font>c.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>][col<font color='#5555FF'>-</font>c.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>], 
                             img[<font face='Lucida Console'>(</font>row<font color='#5555FF'>-</font>origin.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_out_scale<font color='#5555FF'>/</font>zoom_in_scale][<font face='Lucida Console'>(</font>col<font color='#5555FF'>-</font>origin.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_out_scale<font color='#5555FF'>/</font>zoom_in_scale]<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// now draw all the overlay rectangles
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> rectangle orect <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_rect <font color='#5555FF'>=</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, orect, <font color='#BB00BB'>invert_pixel</font><font face='Lucida Console'>(</font>overlay_rects[i].color<font face='Lucida Console'>)</font>, area<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlighted_rect <font color='#5555FF'>&lt;</font> overlay_rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> highlighted_rect <font color='#5555FF'>=</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// Draw the rectangle wider and with a slightly different color that tapers
</font>                <font color='#009900'>// out at the edges of the line.
</font>                hsi_pixel temp;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp, overlay_rects[i].color<font face='Lucida Console'>)</font>;
                temp.s <font color='#5555FF'>=</font> <font color='#979000'>255</font>;
                temp.h <font color='#5555FF'>=</font> temp.h <font color='#5555FF'>+</font> <font color='#979000'>20</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.i <font color='#5555FF'>&lt;</font> <font color='#979000'>245</font><font face='Lucida Console'>)</font>
                    temp.i <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>;
                rgb_pixel p;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>p, temp<font face='Lucida Console'>)</font>;
                rgb_alpha_pixel po, po2;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>po, p<font face='Lucida Console'>)</font>;
                po.alpha <font color='#5555FF'>=</font> <font color='#979000'>160</font>;
                po2 <font color='#5555FF'>=</font> po;
                po2.alpha <font color='#5555FF'>=</font> <font color='#979000'>90</font>;
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>grow_rect</font><font face='Lucida Console'>(</font>orect,<font color='#979000'>2</font><font face='Lucida Console'>)</font>, po2, area<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>grow_rect</font><font face='Lucida Console'>(</font>orect,<font color='#979000'>1</font><font face='Lucida Console'>)</font>, po, area<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, orect, p, area<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font>orect,<font color='#979000'>1</font><font face='Lucida Console'>)</font>, po, area<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font>orect,<font color='#979000'>2</font><font face='Lucida Console'>)</font>, po2, area<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, orect, overlay_rects[i].color, area<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>overlay_rects[i].label.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// make a rectangle that is at the spot we want to draw our string
</font>                rectangle <font color='#BB00BB'>r</font><font face='Lucida Console'>(</font>orect.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,  c.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c, r, overlay_rects[i].label, overlay_rects[i].color, <font color='#979000'>0</font>, 
                                   std::string::npos, area<font face='Lucida Console'>)</font>;
            <b>}</b>


            <font color='#009900'>// draw circles for each "part" in this overlay rectangle.
</font>            std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font>::const_iterator itr;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>itr <font color='#5555FF'>=</font> overlay_rects[i].parts.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; itr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> overlay_rects[i].parts.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>itr<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second <font color='#5555FF'>=</font><font color='#5555FF'>=</font> OBJECT_PART_NOT_PRESENT<font face='Lucida Console'>)</font>
                    <font color='#0000FF'>continue</font>;

                rectangle temp <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second,<font color='#979000'>1</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, part_width, part_width<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_rect <font color='#5555FF'>=</font><font color='#5555FF'>=</font> i <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                    selected_part_name.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_part_name <font color='#5555FF'>=</font><font color='#5555FF'>=</font> itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>, temp.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>, <font color='#BB00BB'>invert_pixel</font><font face='Lucida Console'>(</font>overlay_rects[i].color<font face='Lucida Console'>)</font>, area<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c, <font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>, temp.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>, overlay_rects[i].color, area<font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#009900'>// make a rectangle that is at the spot we want to draw our string
</font>                rectangle <font color='#BB00BB'>r</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> temp.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>,  
                            c.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c, r, itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first, overlay_rects[i].color, <font color='#979000'>0</font>, 
                                   std::string::npos, area<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>overlay_rects[i].crossed_out<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_rect <font color='#5555FF'>=</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, orect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, orect.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>invert_pixel</font><font face='Lucida Console'>(</font>overlay_rects[i].color<font face='Lucida Console'>)</font>, area<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, orect.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, orect.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>invert_pixel</font><font face='Lucida Console'>(</font>overlay_rects[i].color<font face='Lucida Console'>)</font>, area<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, orect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, orect.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,overlay_rects[i].color, area<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, orect.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, orect.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,overlay_rects[i].color, area<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// now draw all the overlay lines 
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_lines.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, 
                      zoom_in_scale<font color='#5555FF'>*</font>overlay_lines[i].p1<font color='#5555FF'>/</font>zoom_out_scale <font color='#5555FF'>+</font> origin, 
                      zoom_in_scale<font color='#5555FF'>*</font>overlay_lines[i].p2<font color='#5555FF'>/</font>zoom_out_scale <font color='#5555FF'>+</font> origin, 
                      overlay_lines[i].color, area<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#009900'>// now draw all the overlay circles 
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_circles.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point center <font color='#5555FF'>=</font> zoom_in_scale<font color='#5555FF'>*</font>overlay_circles[i].center<font color='#5555FF'>/</font>zoom_out_scale <font color='#5555FF'>+</font> origin;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> radius <font color='#5555FF'>=</font> zoom_in_scale<font color='#5555FF'>*</font>overlay_circles[i].radius<font color='#5555FF'>/</font>zoom_out_scale;
            <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c, 
                      center, 
                      radius, 
                      overlay_circles[i].color, area<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>overlay_circles[i].label.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> point temp <font color='#5555FF'>=</font> center <font color='#5555FF'>+</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,radius<font face='Lucida Console'>)</font>;

                <font color='#009900'>// make a rectangle that is at the spot we want to draw our string
</font>                rectangle <font color='#BB00BB'>r</font><font face='Lucida Console'>(</font>temp,  c.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c, r, overlay_circles[i].label, overlay_circles[i].color, <font color='#979000'>0</font>, 
                                   std::string::npos, area<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, rect_to_draw, <font color='#BB00BB'>invert_pixel</font><font face='Lucida Console'>(</font>default_rect_color<font face='Lucida Console'>)</font>, area<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>on_keydown</font><font face='Lucida Console'>(</font>key,is_printable, state<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>is_printable <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect_is_selected <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
            <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_BACKSPACE <font color='#5555FF'>|</font><font color='#5555FF'>|</font> key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DELETE<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            moving_overlay <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_part_name.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                overlay_rects.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>overlay_rects.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> selected_rect<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                overlay_rects[selected_rect].parts.<font color='#BB00BB'>erase</font><font face='Lucida Console'>(</font>selected_part_name<font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_printable <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect_is_selected <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>i</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            overlay_rects[selected_rect].crossed_out <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>overlay_rects[selected_rect].crossed_out;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='add_labelable_part_name'></a>add_labelable_part_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>part_names.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font>.second<font face='Lucida Console'>)</font>
        <b>{</b>
            member_function_pointer<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font color='#5555FF'>&gt;</font> mfp;
            mfp.<font color='#BB00BB'>set</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>image_display::on_part_add<font face='Lucida Console'>)</font>;
            parts_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Add </font>" <font color='#5555FF'>+</font> name,impl::<font color='#BB00BB'>image_display_functor</font><font face='Lucida Console'>(</font>name,mfp<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='clear_labelable_part_names'></a>clear_labelable_part_names</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        part_names.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parts_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> is_double_click
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>on_mouse_down</font><font face='Lucida Console'>(</font>btn, state, x, y, is_double_click<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>enabled<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image_clicked_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            point <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
            p <font color='#5555FF'>-</font><font color='#5555FF'>=</font> origin;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                p <font color='#5555FF'>=</font> p<font color='#5555FF'>/</font>zoom_in_scale;
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                p <font color='#5555FF'>=</font> p<font color='#5555FF'>*</font>zoom_out_scale;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dlib::<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>image_clicked_handler</font><font face='Lucida Console'>(</font>p, is_double_click, btn<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>overlay_editing_enabled<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>bool</u></font> rect_was_selected <font color='#5555FF'>=</font> rect_is_selected;
            rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>long</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> best_idx <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            std::string best_part;

            <font color='#009900'>// check if this click landed on any of the overlay rectangles
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle orect <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>distance_to_rect_edge</font><font face='Lucida Console'>(</font>orect, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                <b>{</b>
                    best_dist <font color='#5555FF'>=</font> dist;
                    best_idx <font color='#5555FF'>=</font> i;
                    best_part.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>

                std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font>::const_iterator itr;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>itr <font color='#5555FF'>=</font> overlay_rects[i].parts.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; itr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> overlay_rects[i].parts.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>itr<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second <font color='#5555FF'>=</font><font color='#5555FF'>=</font> OBJECT_PART_NOT_PRESENT<font face='Lucida Console'>)</font>
                        <font color='#0000FF'>continue</font>;

                    rectangle temp <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second,<font color='#979000'>1</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, part_width, part_width<font face='Lucida Console'>)</font>;
                    point c <font color='#5555FF'>=</font> <font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;

                    <font color='#009900'>// distance from edge of part circle
</font>                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>c <font color='#5555FF'>-</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>0.5</font> <font color='#5555FF'>-</font> temp.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                    <b>{</b>
                        best_idx <font color='#5555FF'>=</font> i;
                        best_dist <font color='#5555FF'>=</font> dist;
                        best_part <font color='#5555FF'>=</font> itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first;
                    <b>}</b>
                <b>}</b>
            <b>}</b>


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>best_dist <font color='#5555FF'>&lt;</font> <font color='#979000'>13</font><font face='Lucida Console'>)</font>
            <b>{</b>
                moving_overlay <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                moving_rect <font color='#5555FF'>=</font> best_idx;
                moving_part_name <font color='#5555FF'>=</font> best_part;
                <font color='#009900'>// If we are moving one of the sides  of the rectangle rather than one of
</font>                <font color='#009900'>// the parts circles then we need to figure out which side of the rectangle
</font>                <font color='#009900'>// we are moving.
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>best_part.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// which side is the click closest to?
</font>                    <font color='#0000FF'>const</font> rectangle orect <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font>best_idx<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>const</font> point p <font color='#5555FF'>=</font> <font color='#BB00BB'>nearest_point</font><font face='Lucida Console'>(</font>orect,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'><u>long</u></font> dist_left   <font color='#5555FF'>=</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>orect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'><u>long</u></font> dist_top    <font color='#5555FF'>=</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>orect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'><u>long</u></font> dist_right  <font color='#5555FF'>=</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>orect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'><u>long</u></font> dist_bottom <font color='#5555FF'>=</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>orect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'><u>long</u></font> min_val <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>dist_left,dist_right<font face='Lucida Console'>)</font>,std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>dist_top,dist_bottom<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist_left <font color='#5555FF'>=</font><font color='#5555FF'>=</font> min_val<font face='Lucida Console'>)</font>
                        moving_what <font color='#5555FF'>=</font> MOVING_RECT_LEFT;
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist_top <font color='#5555FF'>=</font><font color='#5555FF'>=</font> min_val<font face='Lucida Console'>)</font>
                        moving_what <font color='#5555FF'>=</font> MOVING_RECT_TOP;
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist_right <font color='#5555FF'>=</font><font color='#5555FF'>=</font> min_val<font face='Lucida Console'>)</font>
                        moving_what <font color='#5555FF'>=</font> MOVING_RECT_RIGHT;
                    <font color='#0000FF'>else</font> 
                        moving_what <font color='#5555FF'>=</font> MOVING_RECT_BOTTOM;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    moving_what <font color='#5555FF'>=</font> MOVING_PART;
                <b>}</b>
                <font color='#009900'>// Do this to make the moving stuff snap to the mouse immediately.
</font>                <font color='#BB00BB'>on_mouse_move</font><font face='Lucida Console'>(</font>state<font color='#5555FF'>|</font>btn,x,y<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_was_selected<font face='Lucida Console'>)</font>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect_is_selected<font face='Lucida Console'>)</font>
        <b>{</b>
            last_right_click_pos <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
            parts_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::CONTROL<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>drawing_rect<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> best_idx <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#009900'>// check if this click landed on any of the overlay rectangles
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle orect <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>distance_to_rect_edge</font><font face='Lucida Console'>(</font>orect, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                <b>{</b>
                    best_dist <font color='#5555FF'>=</font> dist;
                    best_idx <font color='#5555FF'>=</font> i;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>best_dist <font color='#5555FF'>&lt;</font> <font color='#979000'>13</font><font face='Lucida Console'>)</font>
            <b>{</b>
                overlay_rects[best_idx].label <font color='#5555FF'>=</font> default_rect_label;
                overlay_rects[best_idx].color <font color='#5555FF'>=</font> default_rect_color;
                highlighted_rect <font color='#5555FF'>=</font> best_idx;
                highlight_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                highlight_timer.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>return</font>;
        <b>}</b>


        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>is_double_click <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            drawing_rect <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            rect_anchor <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected<font face='Lucida Console'>)</font>
            <b>{</b>
                rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected<font face='Lucida Console'>)</font>
            <b>{</b>
                rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            drawing_rect <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_double_click<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>bool</u></font> rect_was_selected <font color='#5555FF'>=</font> rect_is_selected;
            rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>long</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> best_idx <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            std::string best_part;

            <font color='#009900'>// check if this click landed on any of the overlay rectangles
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> overlay_rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle orect <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>distance_to_rect_edge</font><font face='Lucida Console'>(</font>orect, <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                <b>{</b>
                    best_dist <font color='#5555FF'>=</font> dist;
                    best_idx <font color='#5555FF'>=</font> i;
                    best_part.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>

                std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font>::const_iterator itr;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>itr <font color='#5555FF'>=</font> overlay_rects[i].parts.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; itr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> overlay_rects[i].parts.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>itr<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second <font color='#5555FF'>=</font><font color='#5555FF'>=</font> OBJECT_PART_NOT_PRESENT<font face='Lucida Console'>)</font>
                        <font color='#0000FF'>continue</font>;

                    rectangle temp <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect_on_screen</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second,<font color='#979000'>1</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, part_width, part_width<font face='Lucida Console'>)</font>;
                    point c <font color='#5555FF'>=</font> <font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;

                    <font color='#009900'>// distance from edge of part circle
</font>                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>c <font color='#5555FF'>-</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>0.5</font> <font color='#5555FF'>-</font> temp.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                    <b>{</b>
                        best_idx <font color='#5555FF'>=</font> i;
                        best_dist <font color='#5555FF'>=</font> dist;
                        best_part <font color='#5555FF'>=</font> itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first;
                    <b>}</b>
                <b>}</b>
            <b>}</b>


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>best_dist <font color='#5555FF'>&lt;</font> <font color='#979000'>13</font><font face='Lucida Console'>)</font>
            <b>{</b>
                rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>part_names.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    parts_menu.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                selected_rect <font color='#5555FF'>=</font> best_idx;
                selected_part_name <font color='#5555FF'>=</font> best_part;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>orect_selected_event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>orect_selected_event_handler</font><font face='Lucida Console'>(</font>overlay_rects[best_idx]<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected <font color='#5555FF'>|</font><font color='#5555FF'>|</font> rect_was_selected<font face='Lucida Console'>)</font>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect_is_selected<font face='Lucida Console'>)</font>
        <b>{</b>
            rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    std::vector<font color='#5555FF'>&lt;</font>image_display::overlay_rect<font color='#5555FF'>&gt;</font> image_display::
    <b><a name='get_overlay_rects'></a>get_overlay_rects</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> overlay_rects;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='set_default_overlay_rect_label'></a>set_default_overlay_rect_label</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> label
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        default_rect_label <font color='#5555FF'>=</font> label;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    std::string image_display::
    <b><a name='get_default_overlay_rect_label'></a>get_default_overlay_rect_label</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> default_rect_label;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='set_default_overlay_rect_color'></a>set_default_overlay_rect_color</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rgb_alpha_pixel<font color='#5555FF'>&amp;</font> color
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        default_rect_color <font color='#5555FF'>=</font> color;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rgb_alpha_pixel image_display::
    <b><a name='get_default_overlay_rect_color'></a>get_default_overlay_rect_color</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> default_rect_color;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>on_mouse_up</font><font face='Lucida Console'>(</font>btn,state,x,y<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            point c1 <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> origin;
            point c2 <font color='#5555FF'>=</font> rect_anchor <font color='#5555FF'>-</font> origin;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
            <b>{</b>
                c1 <font color='#5555FF'>=</font> c1<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_in_scale;
                c2 <font color='#5555FF'>=</font> c2<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_in_scale;
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
            <b>{</b>
                c1 <font color='#5555FF'>=</font> c1<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_out_scale;
                c2 <font color='#5555FF'>=</font> c2<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_out_scale;
            <b>}</b>

            rectangle <font color='#BB00BB'>new_rect</font><font face='Lucida Console'>(</font>c1,c2<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// When we are zoomed in we adjust the rectangles a little so they
</font>                <font color='#009900'>// are drown surrounding the pixels inside the rect.  This adjustment
</font>                <font color='#009900'>// is necessary to make this code consistent with this goal.
</font>                new_rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
                new_rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            <b>}</b>


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> new_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_rect</font><font face='Lucida Console'>(</font>new_rect, default_rect_color, default_rect_label<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect<font face='Lucida Console'>)</font>
        <b>{</b>
            drawing_rect <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_overlay<font face='Lucida Console'>)</font>
        <b>{</b>
            moving_overlay <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        scrollable_region::<font color='#BB00BB'>on_mouse_move</font><font face='Lucida Console'>(</font>state,x,y<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled<font face='Lucida Console'>)</font>
            <b>{</b>
                rectangle <font color='#BB00BB'>new_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>, rect_anchor<font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>new_rect <font color='#5555FF'>+</font> rect_to_draw<font face='Lucida Console'>)</font>;
                rect_to_draw <font color='#5555FF'>=</font> new_rect;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                drawing_rect <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
            moving_overlay <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_overlay<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::RIGHT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state<font color='#5555FF'>&amp;</font>base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// map point(x,y) into the image coordinate space.
</font>                point p <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_what <font color='#5555FF'>=</font><font color='#5555FF'>=</font> MOVING_PART<font face='Lucida Console'>)</font>
                        p <font color='#5555FF'>=</font> p<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_in_scale<font color='#5555FF'>-</font><font color='#BB00BB'>dpoint</font><font face='Lucida Console'>(</font><font color='#979000'>0.5</font>,<font color='#979000'>0.5</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font>
                        p <font color='#5555FF'>=</font> p<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_in_scale;
                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    p <font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>zoom_out_scale;
                <b>}</b>


                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_what <font color='#5555FF'>=</font><font color='#5555FF'>=</font> MOVING_PART<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>overlay_rects[moving_rect].parts[moving_part_name] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> p<font face='Lucida Console'>)</font>
                    <b>{</b>
                        overlay_rects[moving_rect].parts[moving_part_name] <font color='#5555FF'>=</font> p;
                        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>else</font> 
                <b>{</b>
                    rectangle original <font color='#5555FF'>=</font> overlay_rects[moving_rect].rect;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_what <font color='#5555FF'>=</font><font color='#5555FF'>=</font> MOVING_RECT_LEFT<font face='Lucida Console'>)</font>
                        overlay_rects[moving_rect].rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay_rects[moving_rect].rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_what <font color='#5555FF'>=</font><font color='#5555FF'>=</font> MOVING_RECT_RIGHT<font face='Lucida Console'>)</font>
                        overlay_rects[moving_rect].rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, overlay_rects[moving_rect].rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>moving_what <font color='#5555FF'>=</font><font color='#5555FF'>=</font> MOVING_RECT_TOP<font face='Lucida Console'>)</font>
                        overlay_rects[moving_rect].rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, overlay_rects[moving_rect].rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font> 
                        overlay_rects[moving_rect].rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, overlay_rects[moving_rect].rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>original <font color='#5555FF'>!</font><font color='#5555FF'>=</font> overlay_rects[moving_rect].rect<font face='Lucida Console'>)</font>
                    <b>{</b>
                        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                moving_overlay <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_wheel_up'></a>on_wheel_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// disable mouse wheel if the user is drawing a rectangle
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#009900'>// if CONTROL is not being held down
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::CONTROL<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            scrollable_region::<font color='#BB00BB'>on_wheel_up</font><font face='Lucida Console'>(</font>state<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>enabled<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;


        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>&lt;</font> <font color='#979000'>100</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> zoom_out_scale <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>mouse_loc</font><font face='Lucida Console'>(</font>lastx, lasty<font face='Lucida Console'>)</font>;
            <font color='#009900'>// the pixel in img that the mouse is over
</font>            <font color='#0000FF'>const</font> point pix_loc <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_in_scale;

            zoom_in_scale <font color='#5555FF'>=</font> zoom_in_scale<font color='#5555FF'>*</font><font color='#979000'>10</font><font color='#5555FF'>/</font><font color='#979000'>9</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>;

            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale, img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font face='Lucida Console'>)</font>;

            <font color='#009900'>// make is to the pixel under the mouse doesn't move while we zoom
</font>            <font color='#0000FF'>const</font> point delta <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> pix_loc<font color='#5555FF'>*</font>zoom_in_scale<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, delta<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>mouse_loc</font><font face='Lucida Console'>(</font>lastx, lasty<font face='Lucida Console'>)</font>;
            <font color='#009900'>// the pixel in img that the mouse is over
</font>            <font color='#0000FF'>const</font> point pix_loc <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_out_scale;

            zoom_out_scale <font color='#5555FF'>=</font> zoom_out_scale<font color='#5555FF'>*</font><font color='#979000'>9</font><font color='#5555FF'>/</font><font color='#979000'>10</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_out_scale <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                zoom_out_scale <font color='#5555FF'>=</font> <font color='#979000'>1</font>;

            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale, img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale<font face='Lucida Console'>)</font>;

            <font color='#009900'>// make is to the pixel under the mouse doesn't move while we zoom
</font>            <font color='#0000FF'>const</font> point delta <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> pix_loc<font color='#5555FF'>/</font>zoom_out_scale<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, delta<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_display::
    <b><a name='on_wheel_down'></a>on_wheel_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// disable mouse wheel if the user is drawing a rectangle
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drawing_rect<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        <font color='#009900'>// if CONTROL is not being held down
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::CONTROL<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            scrollable_region::<font color='#BB00BB'>on_wheel_down</font><font face='Lucida Console'>(</font>state<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>enabled<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;


        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>mouse_loc</font><font face='Lucida Console'>(</font>lastx, lasty<font face='Lucida Console'>)</font>;
            <font color='#009900'>// the pixel in img that the mouse is over
</font>            <font color='#0000FF'>const</font> point pix_loc <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_in_scale;

            zoom_in_scale <font color='#5555FF'>=</font> zoom_in_scale<font color='#5555FF'>*</font><font color='#979000'>9</font><font color='#5555FF'>/</font><font color='#979000'>10</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                zoom_in_scale <font color='#5555FF'>=</font> <font color='#979000'>1</font>;

            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale, img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font face='Lucida Console'>)</font>;

            <font color='#009900'>// make is to the pixel under the mouse doesn't move while we zoom
</font>            <font color='#0000FF'>const</font> point delta <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> pix_loc<font color='#5555FF'>*</font>zoom_in_scale<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, delta<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale <font color='#5555FF'>&gt;</font> <font color='#979000'>10</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point <font color='#BB00BB'>mouse_loc</font><font face='Lucida Console'>(</font>lastx, lasty<font face='Lucida Console'>)</font>;
            <font color='#009900'>// the pixel in img that the mouse is over
</font>            <font color='#0000FF'>const</font> point pix_loc <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_out_scale;

            zoom_out_scale <font color='#5555FF'>=</font> zoom_out_scale<font color='#5555FF'>*</font><font color='#979000'>10</font><font color='#5555FF'>/</font><font color='#979000'>9</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>;

            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale, img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale<font face='Lucida Console'>)</font>;

            <font color='#009900'>// make is to the pixel under the mouse doesn't move while we zoom
</font>            <font color='#0000FF'>const</font> point delta <font color='#5555FF'>=</font> <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>mouse_loc <font color='#5555FF'>-</font> pix_loc<font color='#5555FF'>/</font>zoom_out_scale<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, delta<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//         image_window member functions
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    image_window::
    <b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> :
        gui_img<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>,
        window_has_closed<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        have_last_click<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        mouse_btn<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        clicked_signaler<font face='Lucida Console'>(</font><font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>wm<font face='Lucida Console'>)</font>,
        tie_input_events<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
    <b>{</b>

        gui_img.<font color='#BB00BB'>set_image_clicked_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>, <font color='#5555FF'>&amp;</font>image_window::on_image_clicked<font face='Lucida Console'>)</font>;
        gui_img.<font color='#BB00BB'>disable_overlay_editing</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#009900'>// show this window on the screen
</font>        <font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b> 

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    image_window::
    ~<b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// You should always call close_window() in the destructor of window
</font>        <font color='#009900'>// objects to ensure that no events will be sent to this window while 
</font>        <font color='#009900'>// it is being destructed.  
</font>        <font color='#BB00BB'>close_window</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    base_window::on_close_return_code image_window::
    <b><a name='on_window_close'></a>on_window_close</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        window_has_closed <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        clicked_signaler.<font color='#BB00BB'>broadcast</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> base_window::CLOSE_WINDOW;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> image_window::
    <b><a name='get_next_keypress'></a>get_next_keypress</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> key,
        <font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&amp;</font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> state
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>have_last_keypress <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>window_has_closed <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            <font face='Lucida Console'>(</font>have_last_click <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>tie_input_events<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            clicked_signaler.<font color='#BB00BB'>wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>window_has_closed<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>have_last_keypress<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// Mark that we are taking the key click so the next call to get_next_keypress()
</font>            <font color='#009900'>// will have to wait for another click.
</font>            have_last_keypress <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            key <font color='#5555FF'>=</font> next_key;
            is_printable <font color='#5555FF'>=</font> next_is_printable;
            state <font color='#5555FF'>=</font> next_state;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            key <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            is_printable <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        dlib::drawable_window::<font color='#BB00BB'>on_keydown</font><font face='Lucida Console'>(</font>key,is_printable,state<font face='Lucida Console'>)</font>;

        have_last_keypress <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        next_key <font color='#5555FF'>=</font> key;
        next_is_printable <font color='#5555FF'>=</font> is_printable;
        next_state <font color='#5555FF'>=</font> state;
        clicked_signaler.<font color='#BB00BB'>signal</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='tie_events'></a>tie_events</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        tie_input_events <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='untie_events'></a>untie_events</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        tie_input_events <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> image_window::
    <b><a name='events_tied'></a>events_tied</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> tie_input_events;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> image_window::
    <b><a name='get_next_double_click'></a>get_next_double_click</b> <font face='Lucida Console'>(</font>
        point<font color='#5555FF'>&amp;</font> p,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> mouse_button 
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        p <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font>,<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>have_last_click <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>window_has_closed <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            <font face='Lucida Console'>(</font>have_last_keypress<font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>!</font>tie_input_events<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            clicked_signaler.<font color='#BB00BB'>wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>window_has_closed<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>have_last_click<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// Mark that we are taking the point click so the next call to
</font>            <font color='#009900'>// get_next_double_click() will have to wait for another click.
</font>            have_last_click <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            mouse_button <font color='#5555FF'>=</font> mouse_btn;
            p <font color='#5555FF'>=</font> last_clicked_point;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='on_image_clicked'></a>on_image_clicked</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p,
        <font color='#0000FF'><u>bool</u></font> is_double_click,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_double_click<font face='Lucida Console'>)</font>
        <b>{</b>
            have_last_click <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            last_clicked_point <font color='#5555FF'>=</font> p;
            mouse_btn <font color='#5555FF'>=</font> btn;
            clicked_signaler.<font color='#BB00BB'>signal</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> overlay_line<font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> overlay_circle<font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_line<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>overlay<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='clear_overlay'></a>clear_overlay</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        gui_img.<font color='#BB00BB'>clear_overlay</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> image_window::
    <b><a name='on_window_resized'></a>on_window_resized</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        drawable_window::<font color='#BB00BB'>on_window_resized</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, height;
        <font color='#BB00BB'>get_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
        gui_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width, height<font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_WIDGETs_CPP_
</font>

</pre></body></html>